1

I've just been experimenting with a little bit of Javascript and got to the point of understanding the inheritance concept.

I am able to get an evaluation for the below code:

"".constructor //which evaluates to function String() 

Ok Cool. But why is it that when I do the below code, there is an error?

2.constructor //returns an error 

Basically both are primitives right?, so should there not be an error for the empty string as well?

Hope someone can give me a good explanation that will help me learn this one better. Looking forward to your support.

2
  • 1
    (2).constructor => function Number() ... (Avoids parsing ambiguity for floats with a decimal) Commented Feb 24, 2017 at 13:21
  • @Alex K - omg it worked! Well yeah didn't think of the parens for this one. I guess I will place them next time that I am going to try to do this. God bless and thanks. Finally evaluated to (2).constructor ==> function Number() Commented Feb 24, 2017 at 13:25

1 Answer 1

1

You could spend another dot for the decimal point.

console.log(2..toString()); console.log(2.2.toString());

Or wrap the value in parenthesis.

console.log((2).toString()); console.log((2.2).toString());

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, Nina thank you. The paren idea given by @Alex K worked. But yeah appreciate your support.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.