“{} === null” throws syntax error in developer con

2019-06-21 11:47发布

问题:

This question already has an answer here:

  • Why {} != ( {} ) in JavaScript? 2 answers

Why is it that when i type {} === null into the console it throws

SyntaxError: Unexpected token ===

null === {} gives me false as expected.

回答1:

Because {} is treated as an empty block. You can wrap it in parentheses to force an expression:

({} === null)