cckui

判断 undefined

var aaa = undefined; 
console.log(typeof(aaa) === "undefined"); // true

判断 null

var aaa = null; 
console.log(!aaa && typeof(aaa)!=\'undefined\' && aaa!=0); // true

判断 NaN

var aaa = 0/0;
console.log(isNaN(aaa));  // true

因为 NaN 是 JavaScript 之中唯一不等于自身的值,所以可以如下判断:

var aaa = 0/0;
console.log(aaa !== aaa);  // true

其他数据类型判断

var a = "abcdef";
var b = 12345;
var c= [1,2,3];
var d = new Date();
var e = function(){ console.log(111); }; 


console.log(Object.prototype.toString.call(a)); // -------> [object String];
console.log(Object.prototype.toString.call(b)); //  -------> [object Number];
console.log(Object.prototype.toString.call(c)); //  -------> [object Array];
console.log(Object.prototype.toString.call(d)); //  -------> [object Date];
console.log(Object.prototype.toString.call(e)); //  -------> [object Function]; 

更多请参考:https://www.cnblogs.com/cckui/p/7524585.html

分类:

技术点:

相关文章:

  • 2021-11-20
  • 2021-12-07
  • 2021-12-04
  • 2022-01-07
  • 2021-11-27
  • 2021-12-14
  • 2021-12-14
猜你喜欢
  • 2021-11-27
  • 2019-09-19
  • 2021-11-30
  • 2022-01-07
  • 2021-11-27
  • 2020-10-06
  • 2021-10-16
相关资源
相似解决方案