Skip to content

unicorn/no-typeof-undefined Pedantic

🚧 An auto-fix is still under development.

What it does

Disallow typeof comparisons with undefined.

Why is this bad?

Checking if a value is undefined by using typeof value === 'undefined' is needlessly verbose. It's generally better to compare against undefined directly. The only time typeof is needed is when a global variable potentially does not exists, in which case, using globalThis.value === undefined may be better.

Examples

Examples of incorrect code for this rule:

javascript
typeof foo === "undefined";

Examples of correct code for this rule:

javascript
foo === undefined;

References

Released under the MIT License.