简体   繁体   中英

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:

 '\\'' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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