为什么在严格模式下不允许使用八进制数字文字(什么是变通方法?) [英] Why are Octal numeric literals not allowed in strict mode (and what is the workaround?)
本文介绍了为什么在严格模式下不允许使用八进制数字文字(什么是变通方法?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 JavaScript严格模式?有什么危害?
"use strict";
var x = 010; //Uncaught SyntaxError: Octal literals are not allowed in strict mode.
<h1>Check browser console for errors</h1>
如果开发人员需要使用 Octals (可能会误导)更改数字含义),有解决方法吗?
In case a developer needs to use Octals (which can mistakenly change a numbers meaning), is there a workaround?
推荐答案
问题的为什么部分并不是真的可以回答。
The "why" part of the question is not really answerable.
至于如何,我的头顶......
As for "how", off the top of my head...
"use strict";
var x = parseInt('010', 8);
document.write(x);
这篇关于为什么在严格模式下不允许使用八进制数字文字(什么是变通方法?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文