Type of operator :- JavaScript

How to use of type of operator ?

  • The typeof operator is used to get the data type (returns a string) of its operand.
  • The operand can be either a literal or a data structure such as a variable, a function, or an object.
  • The operator returns the data type.
  •   Code :-
<!DOCTYPE html> 
<html> 
 
<head> 
 <meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 
 
<body> 
 
 <h1>type of Operator</h1> 
 
 <input type="button" onclick="cal_typeopr();" value="Data Types"> 
 
 <div id="d1"></div> 
 <div id="d2"></div> 
 <div id="d3"></div> 
 <div id="d4"></div> 
 <div id="d5"></div> 
 <div id="d6"></div> 
 
 <script> 
  function cal_typeopr() 
  { 
   var num = 90; 
   var str = "My name"; 
   var ar = [1, 2, 3]; 
   var obj = { 
    a: "1", 
    b: "2", 
    c: "3" 
   }; 
   var bol = true; 
 
   document.getElementById('d1').innerHTML = typeof(num); 
   document.getElementById('d2').innerHTML = typeof(str); 
   document.getElementById('d3').innerHTML = typeof(ar); 
   document.getElementById('d4').innerHTML = typeof(obj); 
   document.getElementById('d5').innerHTML = typeof(bol); 
 
   /*Used for avoiding error*/ 
   document.getElementById('d6').innerHTML = typeof(novar); 
 
  } 
 </script> 
 
</body> 
 
</html>

Type of operator :- JavaScript Type of operator :- JavaScript Reviewed by Network security on June 03, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.