JavaScript | typeof operator

In JavaScript, the typeof operator returns the data type of its operand in the form of a string. Operand can be any object, function or variable.

Syntax:

typeof operand
      OR
typeof (operand)

Examples:

Input: typeof "geeksforgeeks"
Output: string

Input: typeof NaN
Output: number
NaN is also considered as a number.
filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<body>
<p id="GFG"></p>
<script>
document.getElementById("GFG").innerHTML = 
    typeof "Siddharth" + "<br>" +
    typeof 3.14 + "<br>" +
    typeof true + "<br>" +
    typeof NaN + "<br>" +
    typeof [5, 10, 15, 20] + "<br>" +
    typeof {name:'Siddharth', age:20} + "<br>" +
    typeof new Date() + "<br>" +
    typeof function () {} + "<br>" +
    typeof workout + "<br>" +
    typeof null;
</script>
</body>
</html>

chevron_right


Output:

string
number
boolean
number
object
object
object
function
undefined
object


My Personal Notes arrow_drop_up

Lets get started

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.