简体   繁体   English

转义字符的操作顺序

[英]Order of operations of escape characters

I was playing around with strings particularly, I had a javascript program that evaluated 我特别在玩字符串,我有一个评估了

console.log('\\'')
>> '\''

SO i'm trying to understand how the "escape" character order of operations worked. 所以我试图了解操作的“转义”字符顺序是如何工作的。 Is it the case that (here parenthesis enforce order of operations and aren't part of the string actually) 是否属于这种情况(此处括号强制执行操作顺序,实际上并不属于字符串)

'\\'' = '\(\')'

Or is it: 还是:

'\\'' = '(\\)''

That is are the escape operator evaluating from left to right or right to left? 那是逃生运算符从左到右还是从右到左求值?

I realized that the code above doesn't render according to the order of operations: 我意识到上面的代码并没有按照操作顺序进行渲染:

The original problem: 原来的问题:

console.log("\" '\\'' \"")
>> " '\'' "

From left to right so in '\\\\'' first \\\\ then ' - and this will cause error - so '\\\\'' is invalid statement 从左到右,所以在'\\\\''首先是\\\\然后是' -这将导致错误-因此'\\\\''是无效的语句

 '\\\\'' 

but this one is valid: 但这是有效的:

 '\\'' 

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

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