javascriptunicodeoperating-systemfile-encodings

How does JavaScript ensure that programs are written using the Unicode character set?


I have found this sentence while reading one of the JavaScript books:

JavaScript programs are written using the Unicode character set

What I don't understand is, how does JavaScript files makes sure, that whatever I write in .js file, would be a Unicode Character Set?

Does that mean whenever I type using keyboard on my computer, it'd always use Unicode? How does it work?


Solution

  • This means that the language definition employs Unicode charset. In particular, this usually means that string literals can include Unicode chars, and also may mean that identifiers can include some Unicode chars too (I don't know JavaScript, but in particular it's allowed in the Haskell language).

    Now, the JavaScript implementation can choose any way to map bytes in .js file into internal Unicode representation. It may pretend that all .js files are written in UTF-8, or in 7-bit ASCII encoding, or anything else. You need to consult the implementation manual to reveal that.

    And yeah, you need to know that any file consists of bytes, not characters. How characters, that you are typed in editor, converted to bytes stored in the file, is up to your editor (usually it provides a choice between use of local 8-bit encodings, UTF-8 and sometimes UTF-16). How the bytes stored in the file are converted to characters is up to your language implementation (in this case, JavaScript one).