I\'m seeing some weird behavior when I\'m setting the title of an HTML page using JavaScript. If I insert html character references directly into the title the Unicode rend
The best way to work with Unicode characters in JavaScript is to use the characters themselves, using an editor or other tool that can store them in UTF-8 encoding. You will avoid a lot of confusion. Naturally, you need to properly declare the character encoding of your .js or .html file.
The construct 吧
has no special meaning in JavaScript; it is just eight Ascii characters. But if your JavaScript code has been embedded into an HTML document, then it will be processed by HTML rules before passing to the JavaScript interpreter. And the rules vary by HTML version. Yet another reason to avoid such constructs.
So just write
document.title = "吧出";
(Of course, there are very few situations where you should change the title
element content—which is crucial to search engines and many other purposes—in JavaScript, instead of setting it in HTML. But that’s beside the point.)