angularjs - javascript does not accept 0 before any number -


this question has answer here:

var value = 05000; var addvalue = 1; 

if calculate value + addvalue, it's calculating wrong value

 var result = value + addvalue;// it's return value 20481 

see below image quick watch result

enter image description here

but if give value 5000( without 0 before value), it's calculate correct . why?

putting 0 before number makes octal number literal. interpreted in base 8.

for reason - not put leading zeros before numbers. doesn't intend.

if ran code in strict mode, you'd have gotten error instead:

uncaught syntaxerror: octal literals not allowed in strict mode.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -