Ce produit n'est pas pris en charge par le site Datadog que vous avez sélectionné. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: typescript-code-style/strict-equals

Language: TypeScript

Severity: Notice

Category: Best Practices

Description

In JavaScript, == and != comparisons do type coercion, which can be confusing and may introduce potential errors. Use the type-safe equality operators === and !== instead.

Non-Compliant Code Examples

b == c

foobarbaz == true
foobar != 1
plop == undefined
a == b
a != b
typeof a == 'number'
typeof a == 'number'
'string' != typeof a
true == true
2 == 3
2 == 3
'hello' != 'world'
'hello' != 'world'
a == null
a == null
null != a
true == 1
0 != '1'
'wee' == /wee/
typeof a == 'number'
'string' != typeof a
'hello' != 'world'
2 == 3
true == true
true == null
true != null
null == null
null != null
a
==
b
(a) == b
(a) != b
a == (b)
a != (b)
(a) == (b)
(a == b) == (c)
(a != b) != (c)
a == b;
a!=b;
(a + b) == c;
(a + b)  !=  c;
((1) )  ==  (2);

Compliant Code Examples

'foo' != 'bar'
51 == 42
true == true
foobarbaz == null
typeof foo == 'undefined'
a === b
a !== b
a === b
a !== null
a === null
a !== null
null === null
null !== null
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains