Type casting (also called type conversion) means converting a value from one type to another — turning the text "42" into the number 42, for example. It matters because a value read from a form, a file, or user input often arrives as text, even when it represents a number.
let input = "25";
let age = Number(input);
console.log(age); // 25
console.log(age + 5); // 30 — real addition now, not text joininglet count = 7;
let message = "You have " + String(count) + " items.";
console.log(message); // "You have 7 items."Not every piece of text is a valid number. Converting something that isn't produces a special value called NaN ("Not a Number") rather than crashing the program.
console.log(Number("hello")); // NaN
console.log(Number("42")); // 42