If you type in the console
> new Object()
Empty js object will appear in the console and it is expected, but if you type
> {}
You get undefined
It is strange. Doesn’t it ?
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.
Calling a function with
newalways results in a value. Now, your second line,is an empty code block, not an object literal.
Try:
or:
The console parses lines you type as statements, not expressions. An open curly brace at the start of a statement is a block delimiter, therefore, and not the start of an object literal. By including other tokens to force the parser into parsing an expression, you can then begin an object literal.