typeof checks the data type of a variable

typeof returns 6 data types:

  • object
  • undefined
  • string
  • number
  • boolean
  • function

  var a;

  var b=1;

  var c = 'nihao';

  var d =

var a=null;
var b;
var c="nihao";
var d=12;
var e=true;


  

console.log(typeof a);     //object
console.log(typeof b);     //undefined

console.log(b1);           //undefined
console.log(typeof c);     //string
console.log(typeof d);     //number
console.log(typeof e);     //boolean

console.log(function(){});  //function



Note: When the variable is null, the return type is object, which is a continuation of the javascript error; and when the variable does not exist or the variable is not assigned a value, the return type is object;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324929645&siteId=291194637