简体   繁体   English

在JavaScript中转义序列

[英]Escape sequences in javascript

I know that there are escape sequences like \\n \\b etc in javascript as like in other programming languages. 我知道像其他编程语言一样,javascript中也有\\ n \\ b等转义序列。

alert(\\j)=>alerts j ...So what is the role of \\ here?.Which character is escaped?Is it null character? alert(\\ j)=> alert j ...那么\\ here的作用是什么?。哪个字符被转义?是否为空字符?

None. 没有。 \\j isn't a recognized escape, so the escaping is ignored and "j" is used instead. \\j不是公认的转义符,因此忽略转义并使用“j”代替。

js> "\j"
"j"

Special characters in JavaScript Strings include ' , " , \\ , n , r , t , b , and f , as per JavaScript Special Characters w3schools . Because j is not a special character and \\ is (must itself be escaped to be displayed), it would make sense that the \\ is simply ignored. JavaScript字符串中的特殊字符包括'"\\nrtbf ,根据JavaScript特殊字符w3schools 。因为j 不是特殊字符而且 \\ (必须将其自身转义才能显示),它将使意义上说, \\被简单地忽略。

\\ plays no role in "\\j" . \\"\\j"中没有任何作用。

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

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