On Thu, Jan 13, 2011 at 6:11 PM, Amit Agarwal <lifea...@gmail.com> wrote:

> I really didn't expect any output. It was doing fine until I used new.
> Without new it returns a number object. But when I tried to use new and
> logged it on the console, there I saw this output. Couldn't understand
> whether its a number or its an object.


When you do new Number(2), a new Number _object_ is created. It's "primitive
value" is set to 2. This is different from doing Number(2), so without the
"new" keyword. That would return the primitive number value 2.

Why? Well, simply because that's how the specification says it should be.

So;

2 == 2
Number(2) == 2
new Number(2) == a new object with primitive value 2

- peter

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to