In JavaScript we can use the below line of code(which uses Unicode) for displaying copyright symbol:
var x = "\u00A9 RPeripherals";
Why can’t we type the copyright symbol directly using ALT code (alt+0169) like below :
var x = "© RPeripherals" ;
What is the difference between these two methods?
Who says so? Of course you can. Just configure your code editor to use UTF-8 encoding for source files. You should never use anything else to begin with…
The difference is that using the
\uXXXXscheme you are transmitting at best 2 and at worst 5 extra bytes on the wire. This kind of spelling may help if you need to embed characters in your source code, which your font cannot display properly. For example, I don’t have traditional Chinese characters in the font I’m using for programming, so if I type Chinese characters into my code editor, I’ll see a bunch of question marks or rectangles with Unicode codepoint digits instead of actual characters. But someone who has Chinese glyphs in the font wouldn’t have that problem.If me and that person want to share our source code, it would be preferable that the other person uses
\uXXXXscheme, as I would be able to verify which character is that by looking it up in the Unicode table. That’s about all the difference.EDIT
ECMAScript standard (v 262/5.1) says specifically that
So, the standard guarantees that character encoding is Unicode, and enforces the use of UTF-16 (that’s strange, I thought it was UTF-8), but I don’t think that this is what happens in practice… I believe that browsers use UTF-8 as default. Perhaps this have changed in the later standards, but this is the one last universally accepted.