简体   繁体   English

javascript字符串中带有转义unicode字符的字符串和未转义的unicode字符有什么区别?

[英]What is the difference between a string with escaped unicode characters and non-escaped unicode characters in javascript strings?

In javascript, especially in JSON, we can represent unicode characters with escape sequences or direct unicode string. 在javascript中,尤其是在JSON中,我们可以用转义序列或直接unicode字符串表示unicode字符。

How does the two differ? 两者有何不同? Is there any practical implications or pitfalls in using one over another? 相互使用是否有任何实际影响或陷阱?

Escape sequences use ASCII characters so can be represented without having to worry about the encoding that the JS or JSON is transmitted / saved using. 转义序列使用ASCII字符,因此可以表示它而不必担心JS或JSON使用传输/保存的编码。 They require more bytes per encoded character. 每个编码字符需要更多字节。 They aren't easy for a human to read by looking at source code. 对于人类来说,通过查看源代码来阅读它们并不容易。

None of the above are true when using a Unicode encoding (such as UTF-8). 当使用Unicode编码(例如UTF-8)时,以上都不是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM