Check the type of a variable in JavaScript using `typeof`
July 14, 2022 ‐ 1 min read
To check the type of a given variable or value we use the typeof operator, which returns the type as a string.
const input = "1";
const type = typeof input;
console.log(type);
//=> 'string'
The possible return values of the typeof operator are:
undefinedbooleannumberstringobjectbigintsymbolfunction
There is a gotcha here, odd enough the type of the value null is "object", for the historic reason why I recommend to read why at 2ality.com.