What is typeof operator?

Technology CommunityCategory: JavaScriptWhat is typeof operator?
VietMX Staff asked 3 years ago

JavaScript provides a typeof operator that can examine a value and tell you what type it is:

 let a; 
 typeof a; // "undefined" 
 
 a = "hello world"; 
 typeof a; // "string" 
 
 a = 42;  
 typeof a; // "number" 
 
 a = true;  
 typeof a; // "boolean" 
 
 a = null;  
 typeof a; // "object" -- weird, bug 
 
 a = undefined;  
 typeof a; // "undefined" 
 
 a = ["a", "b", "c"]; 
 typeof a; // "object" 
 
 a = { b: "c" }; 
 typeof a; // "object"