基础

it2022-05-05  135

1 > js基本数据类型:string number boolean function undefined object  Symbol(新增)

2 > typeof 操作符 判断数据类型  ps:typeof null = object;

var x = 1;

if(function fn(){}){   //不算声明函数

  console.log(x+=typeof fn);

}

ps:'1undefined'

tips: typeof 判断数据是否是上述六个基本数据类型 当遇到引用类型的值 即判断具体的数组 对象 正则时 用instanceof判断。  

var person = {name:'xixi'} person instanceof Object  //true

var arr = [1,2,3]; arr instanceof Array; //true

3>var a = [0];

if([0]){

  console.log(a == true);

}else{

  console.log('hehe');

}

//false

reason:if判断时返回false的情况为

“”空字符串数字0undefinednullfalse          因此 if()为真,执行(a==true)的时候,实际上是把数组转换为字符串,而后转为数字 ==》(Number(a.toString()) == true)0==true ==》false

 Ⅳ

[typeof null,null instanceof Object]  ==> ["Object" false]      历史遗留问题 typeof null == "Object";但是null不是Object的实例  Null 的值只有"null" Null也是一种数据类型

转载于:https://www.cnblogs.com/liuxinxin4288/p/8478770.html

相关资源:Java从零基础到精通详细笔记高清完整PDF版

最新回复(0)