typeof operator returns the type of a variable, object, function or expression: - Javascript Operator

Javascript examples for Operator:typeof

Introduction

here is the rules of typeof

  • The data type of NaN is number
  • The data type of an array is object
  • The data type of a date is object
  • The data type of null is object
  • The data type of an undefined variable is undefined

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
    typeof "Hi" + "<br>" +
    typeof 3.14 + "<br>" +
    typeof NaN + "<br>" +
    typeof false + "<br>" +
    typeof [1, 2, 3, 4] + "<br>" +
    typeof {name:'Name', age:34} + "<br>" +
    typeof new Date() + "<br>" +
    typeof function () {} + "<br>" +
    typeof myNumber + "<br>" +
    typeof null;/*from w ww  . j a v a 2s.  c  om*/
</script>

</body>
</html>

Related Tutorials