devnotes.

Type Coercion and Conversion

JavaScript automatically converts values between types in many situations — this is called implicit coercion — but you can also convert explicitly.

console.log("5" + 3);      // "53" — string concatenation
console.log("5" - 3);      // 2    — numeric subtraction

console.log(Number("42")); // 42   — explicit conversion to number
console.log(String(42));   // "42" — explicit conversion to string
console.log(Boolean(""));  // false
console.log(Boolean("0")); // true — any non-empty string is truthy

The + operator prefers string concatenation whenever either operand is a string, while -, *, and / force both operands to be converted to numbers first.

Understanding falsy values (false, 0, "", null, undefined, NaN) versus truthy values (everything else) is essential for writing correct if conditions and default-value patterns, since JavaScript coerces any value used in a boolean context automatically.