- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: javascript-best-practices/valid-typeof
Language: JavaScript
Severity: Warning
Category: Error Prone
Always compare typeof expressions against strings and make sure they are the correct values.
typeof foo === 'strnig';
'strnig' === typeof foo;
if (typeof bar === 'umdefined') {};
typeof foo !== 'strnig';
'strnig' !== typeof foo;
if (typeof bar !== 'umdefined') {};
typeof foo != 'strnig';
'strnig' != typeof foo;
if (typeof bar != 'umdefined') {};
typeof foo == 'strnig';
'strnig' == typeof foo;
if (typeof bar == 'umdefined') {};
if (typeof bar === `umdefined`) {};
typeof foo == 'invalid string';
if (typeof bar !== undefined) {};
typeof foo == Object;
typeof foo == {};
typeof foo === undefined;
undefined === typeof foo;
undefined == typeof foo;
typeof foo === `undefined${foo}`;
typeof foo === `${string}`;
typeof foo === 'string';
typeof foo === 'object';
typeof foo === 'function';
typeof foo === 'undefined';
typeof foo === 'boolean';
typeof foo === 'number';
typeof foo === 'bigint';
'string' === typeof foo;
'object' === typeof foo;
'function' === typeof foo;
'undefined' === typeof foo;
'boolean' === typeof foo;
'number' === typeof foo;
typeof foo === typeof bar;
typeof foo === baz;
typeof foo !== someType;
typeof bar != someType;
someType === typeof bar;
someType == typeof bar;
typeof foo == 'string';
typeof(foo) === 'string';
typeof(foo) !== 'string';
typeof(foo) == 'string';
typeof(foo) != 'string';
var oddUse = typeof foo + 'thing';
// since we don't have optios we are enforcing to always compare agaisnt strings
// function f(undefined) { typeof x === undefined };
typeof foo === 'number';
typeof foo === "number";
var baz = typeof foo + 'thing';
typeof foo === typeof bar;
typeof foo === `string`;
`object` === typeof foo;
// not supported by this rule, we cannot pretend that somethingElse will complete 'string'
// typeof foo === `str${somethingElse}`;