最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

escaping - Why "01" === "u0001" is true in javascript? - Stack Overflow

programmeradmin12浏览0评论

the code is:

console.log("\1" === "\u0001");//true
console.log("\01" === "\x01");//true
console.log("\001" === "\u0001");//true

why "\001" === "\u0001" is true,who can tell me why?

the code is:

console.log("\1" === "\u0001");//true
console.log("\01" === "\x01");//true
console.log("\001" === "\u0001");//true

why "\001" === "\u0001" is true,who can tell me why?

Share Improve this question edited Jul 26, 2014 at 4:15 hippietrail 17.1k21 gold badges109 silver badges179 bronze badges asked Oct 10, 2012 at 15:30 artwlartwl 3,5827 gold badges41 silver badges55 bronze badges 2
  • 2 Because they're all the same character? If you were expecting the form seen in the literal syntax to be pared, you'd need to escape the \ character. console.log("\\1" === "\\u0001");// false – I Hate Lazy Commented Oct 10, 2012 at 15:34
  • They are all the same character. Those are different ways to escape it. – gen_Eric Commented Oct 10, 2012 at 15:35
Add a ment  | 

1 Answer 1

Reset to default 5

All of those strings are a single character; namely, Unicode code point 1.

Those are different ways of escaping it in the string literal.

发布评论

评论列表(0)

  1. 暂无评论