JavaScript typeof | Find Type of Variable

The typeof operator in JavaScript, is used to find the type of variable/value. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="para1"></p>
   <p id="para2"></p>
   
   <script>
      let x = 10;
      document.getElementById("para1").innerHTML = typeof x;
      document.getElementById("para2").innerHTML = typeof "fresherearth";
   </script>
   
</body>
</html>
Output

JavaScript typeof Syntax

The syntax of typeof operator in JavaScript, is:

typeof x

x refers to the variable or value, whose type we need to find.

JavaScript Online Test


« Previous Tutorial Next Tutorial »