This page is not yet available in Spanish. We are working on its translation. If you have any questions or feedback about our current translation project, feel free to reach out to us!
Metadata
ID:javascript-best-practices/valid-typeof
Language: JavaScript
Severity: Warning
Category: Error Prone
Description
Always compare typeof expressions against strings and make sure they are the correct values.
typeoffoo==='string';typeoffoo==='object';typeoffoo==='function';typeoffoo==='undefined';typeoffoo==='boolean';typeoffoo==='number';typeoffoo==='bigint';'string'===typeoffoo;'object'===typeoffoo;'function'===typeoffoo;'undefined'===typeoffoo;'boolean'===typeoffoo;'number'===typeoffoo;typeoffoo===typeofbar;typeoffoo===baz;typeoffoo!==someType;typeofbar!=someType;someType===typeofbar;someType==typeofbar;typeoffoo=='string';typeof(foo)==='string';typeof(foo)!=='string';typeof(foo)=='string';typeof(foo)!='string';varoddUse=typeoffoo+'thing';// since we don't have optios we are enforcing to always compare agaisnt strings
// function f(undefined) { typeof x === undefined };
typeoffoo==='number';typeoffoo==="number";varbaz=typeoffoo+'thing';typeoffoo===typeofbar;typeoffoo===`string`;`object`===typeoffoo;// not supported by this rule, we cannot pretend that somethingElse will complete 'string'
// typeof foo === `str${somethingElse}`;