✅ This rule is enabled in the recommended
config.
🔧💡 This rule is automatically fixable by the --fix
CLI option and manually fixable by editor suggestions.
Enforce compare value with undefined
directly instead of compare typeof value
with 'undefined'
.
function foo(bar) {
if (typeof bar === 'undefined') {}
}
import foo from './foo.js';
if (typeof foo.bar !== 'undefined') {}
function foo(bar) {
if (foo === undefined) {}
}
import foo from './foo.js';
if (foo.bar !== undefined) {}
Type: boolean
Default: false
This rule ignores variables not defined in file by default.
Set it to true
to check all variables.
// eslint unicorn/no-typeof-undefined: ["error", {"checkGlobalVariables": true}]
if (typeof undefinedVariable === 'undefined') {} // Fails
// eslint unicorn/no-typeof-undefined: ["error", {"checkGlobalVariables": true}]
if (typeof Array === 'undefined') {} // Fails