JavaScript automatically converts values when needed:
Useful when you want predictable behavior in code.
These are used for converting strings to numbers:
parseInt("42px") // 42
parseFloat("3.14abc") // 3.14
parseInt("abc") // NaNNaN stands for "Not a Number":
let x = Number("hello");
console.log(x); // NaN
console.log(isNaN(x)); // trueBoolean(0) // false
Boolean("text") // trueString(), Number(), Boolean() for clarityparseInt() with a radix (e.g., parseInt("10", 10))=== for strict comparisons to avoid coercion issuesAsk the AI if you need help understanding or want to dive deeper in any topic