In JavaScript, what’s the difference between
var x = Object();
and
var x = new Object();
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is pulled directly from the ECMAScript specification:
15.2.1 The Object Constructor Called as a Function
When Object is called as a function rather than as a constructor, it performs a type conversion.
15.2.1.1 Object ( [ value ] )
When the Object function is called with no arguments or with one argument value, the following steps are
taken:
If value is null, undefined or not
supplied, create and return a new
Object object exactly as if the
standard built-in Object
constructor had been called with the
same arguments (15.2.2.1).
In Short:
new Object([ value ])Return ToObject(value).
Notes:
[ ] Is A common way to mark a parameter as optional.
ToObject Is a very simple operation that is defined in section 9.9.