How to check for undefined in JavaScript?

You can use the typeof operator to check if a value was undefined.

if (typeof name === "undefined") {
// code here
}

The typeof operator returns a string indicating the type of the unevaluated operand.

Add a Comment

Your email address will not be published. Required fields are marked *