亞馬遜網(wǎng)網(wǎng)站建設(shè)規(guī)劃報告微信客戶管理
數(shù)據(jù)類型
基本類型
- String: 任意字符串
- Number: 任意的數(shù)字
- boolean: true/false
- undefined: undefined
- null: null
對象類型
- Object: 任意對象
- Function 一種特別的對象(可以執(zhí)行)
- Array: 一種特別的對象
判斷
- typeof //不能區(qū)分?jǐn)?shù)組與對象、null與object
- instanceof //可以區(qū)分對象與數(shù)組
- ===
// 1、typeof 返回數(shù)據(jù)類型的字符串表達(dá)var a;console.log(typeof a==='undefined',typeof a === undefined) //true ,false// 2、對象var b1={b2:[1,'abc',console.log],b3: function(){console.log('b3')}}console.log(b1 instanceof Object, b1 instanceof Array) // true falseconsole.log(b1.b2 instanceof Array,b1.b2 instanceof Object) // true true
問題 var a = xxx , a內(nèi)存中保存的到底是什么
1、xxx 是基本數(shù)據(jù),保存的就是這個數(shù)據(jù)
2、xxx 是對象, 保存的是對象的地址值
3、 xxx 是一個變量, 保存的xxx的內(nèi)存內(nèi)容(可能是基本數(shù)據(jù),也可能是地址)
// obj1 obj2 指向同一個對象 var obj1 = {name: 'Tom'}var obj2 = obj1 obj2.age =12 console.log(obj1.age,obj1.name) //12function fn(obj){obj.name = 'A'}fn(obj1)console.log(obj2.name) //Avar a = {age: 12}var b = aa = {name: 'BOB', age:13}b.age=14console.log(b.age,a.name,a.age) // 14 BOB 13function fn2(obj){obj = {age: 15} //obj 指向了一個新的對象,并未改變原來對象的值}fn2(a)console.log(a.age) // 13
問題 js調(diào)用函數(shù)是傳遞變量參數(shù)時,是值傳遞還是引用傳遞
理解1: 都是值(基本/地址值)傳遞
理解2:可能是值傳遞,也可能是引用傳遞(地址值)
var a = 3;function fn(a){a = a+1}fn(a);console.log(a) //3
問題 JS引擎如何管理內(nèi)存
1、內(nèi)存生命周期
- 分配小內(nèi)存空間,得到它的使用權(quán)
- 存儲數(shù)據(jù),可以反復(fù)進(jìn)行操作
- 釋放小內(nèi)存空間
2、釋放內(nèi)存
- 局部變量: 函數(shù)執(zhí)行完自動釋放
- 對象: 成為垃圾對象 ==》 垃圾回收器回收