The typeof Operator :
typeof is a kind of keyword that returns a string which tells the data type of an expression.
Syntax : `typeof operand`
(The operand used is an expression representing the object or primitive whose type is to be returned.)
The following example tests the data type of variables.
<!DOCTYPE html>
<html>
<body>
<p>The typeof operator returns the type of a variable or an expression.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
typeof "john" + "<br>" + // Returns string
typeof 37 + "<br>" + // Returns Number
typeof 3.14 + "<br>" + // Returns Number
typeof true + "<br>" + // Returns Boolean
typeof false + "<br>" + // Returns Boolean
typeof "" + "<br>" + // Returns string
typeof "bla" + "<br>" + // Returns string
typeof [1,2,3,4] + "<br>" + // Returns object
typeof {name:'john', age:34}; // Returns object
</script>
</body>
</html>
0 Comment(s)