Implicit Coercion in Operations
Predict how + and comparisons coerce types.
Implicit Coercion
Implicit coercion happens when an operator converts operands to a type that the operation needs. Different operators trigger different conversions.
console.log("5" + 1)
console.log("5" - 1)Plus With Strings
The plus operator is special: if either operand is a string, it performs string concatenation instead of numeric addition.
console.log("3" + 4)
console.log(3 + "4")
console.log("a" + 1 + 2)All lessons in this course
- Truthy and Falsy Values
- Loose vs Strict Equality
- Implicit Coercion in Operations
- Explicit Conversion Techniques