The in
operator makes it possible to see whether an object has a property with a particular name.
if ("name" in object) { ... }
Without in
, that would be harder. You can test for null
or undefined
, but that doesn’t answer the question unambiguously.
Note that the token in
also appears in the for ... in
loop:
for (name in object)
That’s the same word in
of course, but in that situation it is not acting as an expression operator; it’s just there as sugar for the syntax.
9
solved What is the benefit of using `in` operators in JavaScript? [closed]