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

the code is:console.log("1" === "u0001");trueconsole.log("1" === &

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745394150a4625800.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信