JBird
JBird

Reputation: 89

Unicode -- What's going on here?

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

Answers (1)

deceze
deceze

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

Related Questions