TYPE CONVERSION


Type Conversion = change the datatype of a value to another


(STRINGS, NUMBERS, BOOLEANS)

Javascript


let age = window.prompt("how old are you?")
age = Number(age) // convert string in number age += 1
console.log("Happy birthday! you are", age, "years old")

Result after typed 21 on window prompt:

Happy birthday! you are 22 years old

let x
let y
let z

x = Number("3.14") // string
y = String(3.14) // number
z = Boolean("pizza")
console.log(x, typeof x) // 'number'
console.log(y, typeof y) // string
console.log(z, typeof z) // true 'boolean'