JavaScript typeof() operator is used to find the data type of a JavaScript variable. This operator returns the type of variables and values.
typeof operand
typeof(operand)
The typeof
operator is not a variable. It is an operator. Operators ( + – * / ) do not have any data type. But, the typeof
operator always returns a string (containing the type of the operand).
JavaScript typeof operator
Simple example code.
<!DOCTYPE html>
<html>
<body>
<script>
const num = 100;
console.log(typeof 100);
console.log(typeof '0');
console.log(typeof false);
</script>
</body>
</html>
Output:

The possible types that are available in JavaScript that typeof
operator returns are:
Types | typeof Result |
---|---|
String | “string” |
Number | “number” |
BigInt | “bigint” |
Boolean | “boolean” |
Object | “object” |
Symbol | “symbol” |
undefined | “undefined” |
null | “object” |
function | “function” |
More Example code
typeof "John" // Returns "string"
typeof 3.14 // Returns "number"
typeof NaN // Returns "number"
typeof false // Returns "boolean"
typeof [1,2,3,4] // Returns "object"
typeof {name:'John', age:34} // Returns "object"
typeof new Date() // Returns "object"
typeof function () {} // Returns "function"
typeof myCar // Returns "undefined" *
typeof null // Returns "object"
Do comment if you have any doubts or suggestions on this JS operator topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.