Back to Content

BroadcastChannel: close() method

files/en-us/web/api/broadcastchannel/close/index.md

latest816 B
Original Source

{{APIRef("BroadCastChannel API")}} {{AvailableInWorkers}}

The close() method of the {{domxref("BroadcastChannel")}} interface terminates the connection to the underlying channel, allowing the object to be garbage collected. This is a necessary step to perform as there is no other way for a browser to know that this channel is not needed anymore.

Syntax

js-nolint
close()

Parameters

None.

Return value

None ({{jsxref("undefined")}}).

Examples

js
// Connect to a channel
const bc = new BroadcastChannel("test_channel");

// More operations (like postMessage, …)

// When done, disconnect from the channel
bc.close();

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("BroadcastChannel")}}, the interface it belongs to.