TextEncoder()

The TextEncoder() constructor returns a newly created utf-8 TextEncoder object.

Syntax

encoder = new TextEncoder();

Parameters

  • TextEncoder() takes no parameters since Firefox 48 and Chrome 53

Note: Prior to Firefox 48 and Chrome 53, an encoding type label was accepted as a paramer to the TextEncoder object, since then both browers have removed support for any encoder type other than utf-8, to match the spec. Any type label passed into the TextEncoder constructor will now be ignored and a utf-8 TextEncoder will be created.

Exceptions

  • TextEncoder() throws no exceptions since Firefox 48 and Chrome 53

Note: Prior to Firefox 48 and Chrome 53 an exception would be thrown for an unknown encoding type.

Specifications

Specification Status Comment
Encoding
The definition of 'TextEncoder()' in that specification.
Living Standard Initial definition

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
TextEncoder() constructor
Experimental
Chrome Full support 53
Notes
Full support 53
Notes
Notes Does not accept parameters. Supports only utf-8 encoding.
No support 38 — 53
Notes
Notes Throws RangeError exception for unknown encoding types.
Edge Full support 79
Notes
Full support 79
Notes
Notes Does not accept parameters. Supports only utf-8 encoding.
Firefox Full support 48
Notes
Full support 48
Notes
Notes The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.
No support 38 — 48
Notes
Notes If the encoding type label argument is invalid, then a RangeError exception is thrown.
No support 19 — 38
Notes
Notes If the encoding type label argument is invalid, then a TypeError exception is thrown.
Full support 18
Notes
Notes Firefox 18 implemented an earlier and slightly different version of the specification.
IE No support NoOpera Full support 25Safari Full support 10.1WebView Android Full support 38Chrome Android Full support 38Firefox Android Full support 48
Notes
Full support 48
Notes
Notes The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.
No support 38 — 48
Notes
Notes If the encoding type label argument is invalid, then a RangeError exception is thrown.
No support 19 — 38
Notes
Notes If the encoding type label argument is invalid, then a TypeError exception is thrown.
Full support 18
Notes
Notes Firefox 18 implemented an earlier and slightly different version of the specification.
Opera Android ? Safari iOS Full support 10.3Samsung Internet Android Full support 3.0

Legend

Full support
Full support
No support
No support
Compatibility unknown
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also