0

i am working with js right now.

i have two objects left and right.

if i check console.log(left !== right) i get true.

now if i check console.log(typeof(left) !== typeof(right)) i get false.

now if i check console.log(left != right) i get true.

if i check both objects in https://www.jsondiff.com/ it says both objects are identical.

how is this possible? i am so confused. can someone help on what could be the possible reason this is happening?

sorry i cannot share exact objects.

mordor619
  • 154
  • 11
  • 1
    Object equality is a different topic altogether in JavaScript. If you are using `===` operator, if both objects are referring to exact same memory location, then only it is going to evaluated as true. If you comparing objects, i.e. comparing all the values of an Object, iterate through all the properties in an object and perform comparison. Or you may use some helper library like lodash. – Rayon Jul 29 '23 at 11:28
  • What you observe will happen for _any_ two objects, unless one has been assigned to the other (by setting `left = right`). Otherwise they are neither equal nor identical (which amounts to the same for objects), but their `typeof` is "object". – Heiko Theißen Jul 29 '23 at 11:31
  • `{} === {}` and `{} == {}` are both `false` in JavaScript. You can't use `==` or `===` to compare objects, you have to iterate over their properties and compare them. – user229044 Jul 29 '23 at 11:31

0 Answers0