JavaScriptEasy
How do you check the data type of a variable?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
To check the data type of a variable in JavaScript, you can use the typeof operator. For example, typeof variableName will return a string indicating the type of the variable, such as "string", "number", "boolean", "object", "function", "undefined", or "symbol". For arrays and null, you can use Array.isArray(variableName) and variableName === null, respectively.
