JS: Source Code Encoding
Following are the details.
ECMAScript code is expressed using Unicode, version 8.0.0 or later. ECMAScript source text is a sequence of code points. All Unicode code point values from U+0000 to U+10FFFF, including surrogate code points, may occur in source text where permitted by the ECMAScript grammars. The actual encodings used to store and interchange ECMAScript source text is not relevant to this specification.
However, it does not specify what encoding is used.
- If the file is embedded in HTML page, then it depends on the encoding used for that page (and other factors such as HTTP header.).
[see HTTP Protocol Tutorial]
… The actual encodings used to store and interchange ECMAScript source text is not relevant to this specification.
Regardless of the external source text encoding, a conforming ECMAScript implementation processes the source text as if it was an equivalent sequence of SourceCharacter values, each SourceCharacter being a Unicode code point. Conforming ECMAScript implementations are not required to perform any normalization of source text, or behave as though they were performing normalization of source text.
// -*- coding: utf-8 -*-
This line indicates what encoding is used for a file, and is standard for Python, Ruby, emacs lisp, and many editors.
This line is completely ignored by browsers. It is only useful for your editors.
However, you still need to save the file in utf-8 encoding. Typically, you can set your editor (such as emacs, vim, XCode, Microsoft Visual Studio, etc, to save file in utf-8.)
[see Ruby: Unicode Tutorial 💎]
[see Emacs: Unicode Tutorial]
- JS: Source Code Encoding
- JS: String Code Unit vs Code Point
- JS: Unicode Character Escape Sequence
- JS: Allowed Characters in Identifier
- HTML: Allowed Characters in id Attribute
- HTML: Character Sets and Encoding
- HTML/XML Entity List
- JS: Template String
- JS: Convert String to Number
- JS: Encode URL, Escape String
- JS: Format Number
- JS: JSON
Ask me question on patreon