CloseEvent: reason property
Websockets API
Websockets API
The **`reason`** read-only property of the CloseEvent interface returns the [WebSocket connection close reason](https://www.rfc-editor.org/info/rfc6455/#section-7.1.6) the server gave for closing the connection; that is, a concise human-readable prose explanation for the closure.
## Value
A string.
## Examples
The following example prints the value of `reason` to the console.
```js
WebSocket.onclose = (event) => {
console.log(event.reason);
};
```
## Specifications
## Browser compatibility
## See also
- [RFC 6455](https://www.rfc-editor.org/info/rfc6455/) (the WebSocket Protocol specification)
source: MDN Web Docs mirror · page
Cite this
"CloseEvent: reason property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/reason JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy