javascript - console.log ('\x' ) 的输出背后的逻辑是什么,其中 x 是任意数字?

标签 javascript node.js

以下示例的输出背后的逻辑是什么:

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/

相关文章:

node.js - 在 Node.js 中测试 dgram 绑定(bind)

node.js - typescript |无法安装类型脚本

android - 当应用程序关闭或未运行时,Android 上的 Cordova 推送插件无法工作

javascript - <th> 使用 javascript 更改点击背景

javascript - 如何测试依赖于注入(inject)数据的范围变量?

javascript - node.js - 使用 Twilio 拨号

javascript - jquery 中的自定义 attr 选择器不起作用?

javascript - 如何在特定时间自动重新加载网页?

node.js - 下载文件,保存并再次读取 --> 错误

javascript - "Uncaught SyntaxError: Unexpected token <"导入时出错