Javascript variable with leading zeroes

前端 未结 3 837
不思量自难忘°
不思量自难忘° 2020-12-21 00:44

Javascript behaves differently with values having leading zeroes. alert(b) - prints different value.

var a = 67116;
var b = 00015;
alert(a);
alert(b);
         


        
3条回答
  •  生来不讨喜
    2020-12-21 01:25

    A leading 0 makes the value an octal literal, so the value you put will be interpreted as a base 8 integer.

    In other words, 015 will be equivalent to parseInt('15', 8).

提交回复
热议问题