以下示例的输出背后的逻辑是什么:
console.log('\272') // -> º
console.log('\364') // -> ô
据我所知,\
是 javascript 中的转义字符,这意味着它会尝试转义后面的字符,但在第一个示例中,它不等于 ASCII 码 72,即字符 H
.
最佳答案
那是因为八进制编码。
Any character with a character code lower than 256 (i.e. any character in the extended ASCII range) can be escaped using its octal-encoded character code, prefixed with . (Note that this is the same range of characters that can be escaped through hexadecimal escapes.)
To use the same example, the copyright symbol ('©') has character code 169, which gives 251 in octal notation, so you could write it as '\251'.
你可以看看这个解释,很说明问题:https://mathiasbynens.be/notes/javascript-escapes
关于javascript - console.log ('\x' ) 的输出背后的逻辑是什么,其中 x 是任意数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55953530/