Reputation: 89
This code:
console.log('π');
console.log('\uD83D\uDE00');
From HTML script tag:
Γ°ΕΈΛβ¬
π
Ran pasted into browser console (same browser):
π
π
What's going on here that causes the first console.log('π'); to fail when it's included with a script tag, but work fine when run in the browser console. The obvious problem seems to be that it isn't being converted to a surrogate pair, since the second line works as expected.
Upvotes: 2
Views: 65
Reputation: 522005
Your HTML file is not saved in the same encoding that the HTTP headers or HTML meta tags advertise. The file is interpreted in the wrong encoding resulting in the wrong characters. That doesn't matter for the unicode escape sequence, which is pure ASCII, it does matter for the non-ASCII literal.
Concrete guess: the file is saved as UTF-8 but advertised as ISO-8859-1.
Upvotes: 5