The charset attribute of the <script> element is used to set character encoding, which is used in an external script file.
Following is the syntax−
<script charset="charset">
Above, set charset, which is the character encoding to be used in an external script file. With “UTF-8”, you can set the character encoding for Unicode. Let us now see an example to implement the charset attribute of the <script> element−
Example
<!DOCTYPE html> <html> <body> <script charset="UTF-8" src="new.js"></script> <p>Displaying the characters with "UTF-8" character set.</p> <p>.</p> </body> </html>
Above, we have used a script file “new.js”, which displays the symbols.