Tutorialspoint.dev

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.
<!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>

Output:

string
number
boolean
number
object
object
object
function
undefined
object


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter