files/en-us/web/api/closeevent/code/index.md
{{APIRef("Websockets API")}}{{AvailableInWorkers}}
The code read-only property of the {{domxref("CloseEvent")}} interface returns a WebSocket connection close code indicating the reason the connection was closed.
An integer WebSocket connection close code in the range 1000 - 4999, indicating the reason the connection was closed.
The following example prints the value of code to the console.
WebSocket.onclose = (event) => {
console.log(event.code);
};
{{Specifications}}
{{Compat}}