An example of using typeof in javascript

  • 2020-03-30 01:00:49
  • OfStack

<title>javascript In the typeof The use of </title> 
//1. Basic types
var x = 123; 
var y = "abc"; 
var z = true; 
//alert(typeof x);//number 
//alert(typeof y);//string 
//alert(typeof z);//boolean 
//2. Reference type. The type is object
var arr = new Array(); 
var date = new Date(); 
var str = new String("abc"); 
//alert(typeof arr);//object 
//alert(typeof date);//object 
//alert(typeof str);//object 
//3. Object type, which can be understood as the simulation of classes in javascript is realized through function
alert(typeof Array);//function 
alert(typeof Date);//function 
alert(typeof String);//function 

Related articles: