SyntaxError: 08 is not a legal ECMA-262 octal constant.

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Post Reply
Bethrezen
Posts: 445
Joined: September 13th, 2003, 11:56 am

SyntaxError: 08 is not a legal ECMA-262 octal constant.

Post by Bethrezen »

Hi all

So ran in to an odd little error and i was hoping someone might know how to fix it so I have an object like this

Code: Select all

var icons = 
{
  icon1: {x: -00822600,  y:  16188000, z:  01169400},
  icon2: {x: -00354600,  y: -03966600, z: -00562800},
  etc...
};
Now when I load this in the browser I get the following error
SyntaxError: 08 is not a legal ECMA-262 octal constant.
Now from what I gather the error is caused by the leading zeros which is causing those values to be treated as octal numbers or base 8 values.

So how can I force numbers with leading zeros to be evaluated as base 10 (decimal) and not base 8 (octal)

now when I used parseInt and set the radix to 10 like so

Code: Select all

var icons = 
{
  icon1: {x: parseInt("-00822600", 10),  y:  16188000, z:  parseInt("01169400", 10)},
  icon2: {x: parseInt("-00354600", 10),  y: parseInt("-03966600", 10), z: parseInt("-00562800", 10)},
  etc...
};
I was able to make the error go away but that has to be one of the messiest and most god awful solutions I've ever seen surely there has to be a smarter cleaner way to handle this?
Post Reply