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")
}
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.