JS的简单复习一

数据类型相关

数据类型

基本数据类型:string、Boolean、number、null、undefined;
引用数据类型:object、array、function;
其中着重说明null和undefined:

  1. null是“无”;
  2. undefined是声明未赋值、函数没有返回值、对象没有赋值属性、调用函数时没有提供参数,该参数为undefined
  3. 1+null=1;1+undefined=NaN;

隐式转换和显式转换

隐式转换技巧:+号、+""、!!等;
显示转换有parseInt()、parseFloat()、.toString()等

数据类型的检测方法(常用)

1.typeof检测情况:

console.log("检测空字符",typeof(''))
console.log("检测字符串",typeof('123'))
console.log("检测数组",typeof([123]))
console.log("检测number",typeof(123))
console.log("检测null",typeof(null))
console.log("检测字符串null",typeof('null'))
console.log("检测undefined",typeof(undefined))
console.log("检测字符串undefined",typeof('undefined'))
console.log("检测object",typeof(Object()))
console.log("检测symbol",typeof(Symbol()))
console.log("检测array",typeof(Array()))
console.log("检测function",typeof(Function()))

在这里插入图片描述
2.instanceof检测:被检测对象 instanceof Array、Object、Function、Date等
3.Object.prototype.toString.call检测:

console.log('检测数组',Object.prototype.toString.call([123]))
console.log('检测null',Object.prototype.toString.call(null))
console.log('检测undefined',Object.prototype.toString.call(undefined))

在这里插入图片描述
4.constructor检测:A.constructor===B
注意:null和undefined检测不到,且.constructor在类继承时会出错。
5.严格等于也可以检测
具体使用哪个因情景使用(简单的理解就是想起哪个使用哪个,然后主要是可以检测出来就行)

深拷贝与浅拷贝

一般说,涉及深拷贝与浅拷贝问题都是对象
浅拷贝:=赋值和Object.assign(target,…sources);
深拷贝:

  1. 手动赋值
  2. JSON.stringify转成字符串再JSON.parse转成对象(处理的对象只有 Number, String, Boolean, Array, 扁平对象)
  3. var newObj = Object.create(oldObj)方法
  4. 递归拷贝
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值