JavaScript 'Listening' for Server Events

Is it possible to have a JavaScript event triggered based on a server event?

for example, let’s say I’m trying to create a chat application -
would the client-side have to constantly send a request to check for new messages, or would the server be able to send an instruction saying that a new message has arrived?