Javascript 0 in beginning of number -
i want understand js logic 0-s in beginning of number. example
var x = 09.3 // here x == 9.3 // other example 09.3 == 9.3 // returns true // check 1 var x = 02.5 // uncaught syntaxerror: unexpected number // or 1 02.5 == 2.5 // same error here can explain, how works, why in first example works, , ignores leading zeros, in second example gives me syntaxerror
thank you
leading 0 on numerical literal indicates octal integer intention, unless second digit 8 or 9. in case, leading 0 ignored.
because octal numeric literals must integers, 02.5 erroneous.
this behavior logged bug in firefox in 2014, because there's javascript code in world , of (probably inadvertently) relies on 09.3 not being syntax error, bug marked "wontfix".
as pointed out in comment below, in "strict" mode octal constants disallowed entirely.
Comments
Post a Comment