基本包装类型

  • 2020 年 10 月 1 日
  • 笔记

基本包装类型就是把简单数据类型包装为复杂数据类型。

var str = ‘andy’;

console.log(str.length);

对象和复杂数据类型才有属性和方法,为什么这里会有length属性呢?

过程为:

var temp = new String(‘andy’);   //包装为复杂数据类型

str = temp; //把临时变量的值给str

temp = null; //会自动销毁这个临时变量