TextDecoder Web API | TextDecoder constructor
In HTML there is a TextDecoder Interface of which we can create a TextDecoder object for the encoding specified in parameter.
Syntax:
decoder = new TextDecoder( utf-Label, option );
Parameters: This constructor accepts two parameters which are mentioned above and described below:
- utf-Label: Label of the encoder in string format. It is “utf-8” as default.
- option: TextDecoderOptions dictionary which has a property fatal (It is a Boolean flag which indicates if the TextDecoder.decode() method should throw DOMException. It’s default value is false.)
Example 1: This example creating a TextDecoder object with “iso-8859-2” as parameter.
<!DOCTYPE html> <html> <head> <title> TextDecoder Web API | TextDecoder constructor </title> </head> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h2>TextDecoder constructor</h2> <button onclick="gettextDecoder ();"> Get textDecoder object </button> <p id='textDecoder'></p> <script type="text/javascript"> function gettextDecoder() { var textDecoder1 = new TextDecoder("iso-8859-2"); console.log(textDecoder1); } </script> </center> </body> </html> |
Output:
- Before Click the button:

- After Click the button:

Example: Create a comment object with nothing as parameter. So the default parameter which is “utf-8” will be taken.
<!DOCTYPE html> <html> <head> <title> TextDecoder Web API | TextDecoder constructor </title> </head> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h2>TextDecoder constructor</h2> <button onclick="gettextDecoder ();"> Get textDecoder object </button> <p id='textDecoder'></p> <script type="text/javascript"> function gettextDecoder() { var textDecoder1 = new TextDecoder(); console.log(textDecoder1); } </script> </center> </body> </html> |
Output:
- Before Click the button:

- After Click the button:

Supported Browsers: The browsers supported by TextDecoder constructor are listed below:
- Google Chrome 38
- Firefox 19
- Opera 25
- Safari 10.1
Recommended Posts:
- JavaScript | RegExp constructor
- HTML | DOM comment() constructor
- How to detect if a function is called as constructor?
- JavaScript | Number constructor Property
- JavaScript | Boolean constructor Property
- JavaScript | Date constructor Property
- JavaScript | Array constructor Property
- JavaScript | Array prototype Constructor
- JavaScript | String constructor Property
- Web DOMRect API | DOMRect() Constructor
- jQuery UI | Tooltip
- CSS | fit-content() Property
- jQuery UI | Tabs
- How to change the placeholder text using jQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh


