Why is it that typing this in the console:
{}.toString
{}.hasOwnProperty
{}....
throws an SyntaxError, and typing:
[].slice
[].filter
({}).toString
({}.toString)
doesn’t?
What is the difference between the Array and the 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.
The problem is the ambiguity of the
{symbol. Try this:When the parser sees
{}at the very beginning of a new statement, it has to choose betweenIt always chooses the second one, a statement block. Thus
{}is an empty statement block, and.toString()right after that makes no sense.There’s no ambiguity with
[]— an[at the beginning of a statement can only be the start of an array literal (as part of an expression statement). However there are similar problems with thefunctionkeyword, which does double-duty as the start of a function declaration statement and the start of a function instantiation expression.