2

Note: It's hard to search for {} == 0 in google

I'm experiencing very exotic behaviour while using node.js:

obj == {}

works, and obviously dumps out false, but

{} == obj

and

{} === obj

Fails with an error: SyntaxError: expected expression, got '=='

Why aren't we allowed to switch rhs and lhs in this case? Why can't we place {} alone on lhs?



const obj = {};

console.log(obj == {});

console.log({} == obj);

console.log({} === obj);
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
Kamila Szewczyk
  • 1,874
  • 1
  • 16
  • 33

0 Answers0