Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
if (typeof x.key != "undefined") { }
if(x.hasOwnProperty("key")){ // … }
Becausebecause
if (x.key)
if(x.key){ // … }
fails if x.key resolves to falseis falsy (for example, x.key ==== "").
x.key
false
x.key ==== ""
Because
fails if x.key resolves to false (for example, x.key = "").
x.key = ""
because
fails if x.key is falsy (for example, x.key === "").
x.key === ""
fails if if x.key resolves to false (egfor example, x.key = "").
if x.key
if (typeof x.key != "undefined"){ }
fails if x.key resolves to false (eg x.key = "").
if (typeof x.key != "undefined"){
} Because
Because iffails (x.key) fails if x.keyif x.key resolves to falsefalse (eg x.key = ""x.key = "").
}
Because if (x.key) fails if x.key resolves to false (eg x.key = "").