Casting#
The conversion surface across the eight types, plus the
== / === contrast.
From / to |
How |
|---|---|
any to string |
|
string to number |
|
string to integer |
|
string to float |
|
any to boolean |
|
number to bigint |
|
bigint to number |
|
== triggers implicit coercion (1 == "1" is true);
=== does not (1 === "1" is false). The operator
writes === and !== by default.
Strict equality compares by type and value.
1 === "1"; // false
Loose equality coerces before comparing.
1 == "1"; // true
== null is the one common, defensible loose form; it
matches both null and undefined in one comparison.
x == null; // true for both null and undefined