I’ve been trying to wrap my head around javascript prototypal inheritance and while reading through John Resig’s book “Pro Javascript Techniques”, I was trying things like this:
alert("me".constructor); //Correctly return String
alert(alert.constructor); //Correctly return Function
However,
alert(55.constructor);//I was expecting Number, but it returns error "SyntaxError: identifier starts immediately after numeric literal" in FF and in IE, it says it is expecting ")"
I also tried other functions that should work on a number, like toFixed() toPrecision() and even toString() but nothing works!
Can someone please explain this behavior?
Put
()around the number, like this:Taken from the comments:
The parser is expecting a decimal number, but fails because it sees the letter “c” instead. Alternatively,
55..constructorwould also work (because55.is just55.0or55).