admin管理员组

文章数量:1426943

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.

本文标签: escapingWhy quot01quotquotu0001quot is true in javascriptStack Overflow