Skip to content

undefinedTypeofChecks

Reports typeof undefined checks.

✅ This rule is included in the ts stylistic presets.

Using typeof x === "undefined" is verbose and can be simplified to x === undefined. Direct comparisons are clearer and more concise.

if (typeof value === "undefined") {
// handle undefined
}
if (typeof value !== "undefined") {
// value is defined
}

This rule is not configurable.

In rare cases where you need to check for undefined in a global scope where undefined might be shadowed, typeof checks are safer. However, in modern JavaScript, this is very uncommon.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.