Nope. They have a difference.
First, it checks to see if the value of window.console Truthy, and the second checks the console property in window .
Suppose you created such a variable.
window.myName = "";
Now if (window.MyName) will not be able to fulfill the condition, since empty lines are false in JavaScript.
console.log(Boolean(window.myName));
But if ("myName" in window) will satisfy the condition, since myName is a property of the window object.
console.log(Boolean("myName" in window));
Note: the in operator will return true even if the property being checked is somewhere in the prototype hierarchy. For instance,
console.log("toString" in {}); // true
Returns true because the {} object inherits the toString method.
If you want to make sure that the property exists on the object itself, you should use Object.prototype.hasOwnProperty , for example
console.log({}.hasOwnProperty("toString")); // false
source share