Type conversion is the process of manually converting from one type to another. Type coercion happens behind the scenes, and JavaScript manages the typing.


Example 1: Type Conversion

const inputYear = "1991" // Input as a string
console.log(inputYear + 18) // Coerces 18 into a string to concatenate into "199118"
 
console.log(Number(inputYear) + 18) // Returns the string as a number

Note

Attempting to convert a non-numerical string into a number will return NaN. Oddly enough, typeof NaN returns number