Student-friendly HTML, CSS, and JavaScript reference with examples
The typeof operator returns the type of a value as a string.
typeof 5 // 'number'
typeof 'hello' // 'string'
typeof true // 'boolean'
typeof undefined // 'undefined'
You can check if two values have the same type:
typeof input1 === typeof input2
const value1 = 5;
const value2 = '5';
typeof value1 // 'number'
typeof value2 // 'string'
typeof value1 === typeof value2 // false
const sameType = typeof input1 === typeof input2;
const isNumber = typeof age === 'number';
const isText = typeof name === 'string';