+ 2
Meaning of javascript error
Function("(")() //Uncaught SyntaxError: Unexpected token } Function("{")() //Uncaught SyntaxError: Unexpected token ) Why does a different symbol give an error? I understand that the code is incorrect, but why is this error? <supplement> Function("+")() , Function("~")() , Function("1+")() //Uncaught SyntaxError: Unexpected token } Function("}+{")() //Uncaught SyntaxError: Single function literal required
2 Réponses
+ 6
Assuming I understand your question correctly, I will attempt to explain.
Function("1")()
doesn't give an error because you correctly define a function prior to it executing. Putting + instead of 1 ends up with an invalid function body of {+} so it complains on seeing the } as it was expecting a valid statement in the function body. Your "}+{" ends up with {}+{} as your code yielding an error at the + after correctly finishing the function.
+ 2
Thank you for answering my question.