CloseEvent: CloseEvent() constructor
Websockets API
Websockets API
The **`CloseEvent()`** constructor creates a new CloseEvent object.
## Syntax
```js-nolint
new CloseEvent(type)
new CloseEvent(type, options)
```
### Parameters
- `type`
- : A string with the name of the event.
It is case-sensitive and browsers always set it to `close`.
- `options`
- : An object that, _in addition of the properties defined in Event()_, has the following properties:
- `wasClean`
- : A boolean value indicating if the connection has been closed cleanly or not. It defaults to `false`.
- `code`
- : An integer representing the _connection close code_ sent by the server. It defaults to `0`.
- `reason`
- : A string containing a human-readable reason describing why the server closed the connection. It defaults to `''`
### Return value
A new CloseEvent object.
## Specifications
## Browser compatibility
## See also
- CloseEvent, the interface of the objects it constructs.
Cite this
"CloseEvent: CloseEvent() constructor". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/CloseEvent JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy