包装类

包装类


 

let aa = new Number(1)
typeof aa   //object

aa + 1 = 2   //2

//new Number   new String  new Boolean

--------------------------------------------------------

let a = new Number(undefined)   //对象类型的number,但是值是NaN
typeof a                        //object

-----------------------------------------------------------

let a = 1234
a.length                  //undefined

----------------------------------------------------------------

var a = 123
a.len = 3
console.log(a.len)     //undefined-->a.len=3-->new Number(a).len = 3-->没有引用,被回收掉了

-------------------------------------------------------------------

let str = '1234'
str.length             //4 -->new String(str).length-->4 
-------------------------------------------------------------

var arr = [1,2,3,4,5]
arr.length = 3
console.log(arr)     //[1,2,3],数组被截断了

--------------------------------------------------------------
var str = 'abc'
str.length = 1     //相当于new String(str).length = 1 
console.log(str)   //abc


------------------------------------------------------------
var name = 'test'
name += 10

var type = typeof(name)   //'string'

if(type.length === 6){
    type.text = 'string'    //new String(type).text = 'string'  -->没用引用,被回收了
}

console.log(type.text)   //undefined

------------------------------------------------------------

var x =1,y = z = 0;//相当于var x = 1,y = 0;z = 0  x与y会被提升

-----------------------------------------------------------------

你可能感兴趣的:(js深度指南,javascript,前端,开发语言)