0

I try to use my object name for an if statement.. but both come up as true, why?

var moduleInfo = new Object("moduleInfo");
moduleInfo ["name"] = "Module: Export"

if (moduleInfo !== "moduleInfo"){
    console.log("window is NOT modulInfo")
    }


if (moduleInfo == "moduleInfo"){
    console.log("window IS modulInfo")
    }
Hensbergen
  • 41
  • 3

1 Answers1

0

The !== is comparing by type, and you are comparing an object with a primitive type of string. replacing either that operator with != or replacing the second one with === will probably get you a more consistent/desired result.

== converts the operands to the same type before making the comparison https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators

Marc Sloth Eastman
  • 693
  • 1
  • 10
  • 19