Calling constructor on number in javascript

I am trying to wrap my head around javascript prototype inheritance and, while reading John Resig's book "About Javascript Techniques", I have tried these things:

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, for example toFixed() toPrecision(), even toString(), but nothing works!

Can someone explain this behavior?

+5
source share
1 answer

Put ()around the number, for example:

alert((55).constructor);

From the comments:

The parser expects a decimal number, but it does not work, because instead it sees the letter "c". Alternatively, 55..constructorit will also work (because 55.- it's simple 55.0or 55).

+6
source

All Articles