JS中是沒有堆和棧的概念,咱們用堆和棧來說解,目的就是方柏霓講解,存儲方式是一致的。html
基礎數據類型進行值傳遞,複雜數據類型進行地址傳遞git
<script> //1.基本數據類型 var str1 = "xiaoliao"; var str2 = str1;//基本數據類型是傳輸的值,引用數據類型傳輸的是內存地址 str1 = "itLike"; console.log(str1); console.log(str2); console.log("========================"); //2.複雜類型 function Person(name,age,intro) { this.name = name; this.age = age; this.intro = intro; } var p1 = new Person("xiaoming",45,"This is a virtuous person!"); var p2 = p1; p1.name = "daliao"; console.log(p1.name); console.log(p2.name);//能夠看出來傳輸的是內容地址 console.log("============================"); //3.基本類型做爲函數的參數 var num1 = 10,num2 = 23; //能夠看出來函數也是值傳遞 fn(num1,num2); console.log("num1="+num1); console.log("num2="+num2); function fn(n1,n2) { n1 *= 2; n2 /= 2; console.log("n1="+n1); console.log("n2="+n2); } console.log("========================="); //4.複雜類型做爲函數參數 function Person(name,age,sex) { this.name = name; this.age = age; this.sex = sex; } function func(person) { person.name = "周杰倫"; } var p = new Person("xiaoming",45,"男"); console.log(p.name) func(p); console.log(p.name);//能夠看出來是地址傳遞 </script>
運行結果github
兩種方法,內置方法instanceof和一種成員方法isArray(變量)數組
//1.檢測一個對象是不是數組 var arr = ["zhansan","lisi","wangwu"]; console.log(arr instanceof Array); console.log(arr instanceof Object);//這句話能夠看出數組也是一種對象 console.log(arr instanceof Function);//數組不是函數類型 //另外一種方法,成員方法 .isArray() console.log(Array.isArray(arr)); console.log(Array.isArray("arr"));
運行結果微信
toString()把數組轉換成字符串,逗號分隔每一項;valueOf成員方法返回數組自己。編輯器
//2.數組經常使用API var arr = ["zhangsan","lisi"]; console.log(arr.toString()); console.log(arr.valueOf());//返回的是數組自己 //3.join(sperator)方法,將數組的元素組成一個字符串,以seperator爲分隔符,省略的話則默認用逗號爲 //分隔符,該方法只接受一個參數:即分隔符。 console.log(arr.join("-")); console.log(arr.join("^")); //4.壓棧,出棧 arr.push("附加的");//返回值就是數組的總長度 console.log(arr.toString()); arr.pop(); console.log(arr.toString()); console.log("======================="); //5.shift()函數,是至關於從頭部進行刪除 arr.push("sdohf"); arr.push("nvl"); console.log(arr.toString()); arr.shift(); console.log(arr.toString());
運行結果函數
https://github.com/ruigege66/JavaScript/blob/master/D20_1_DataExpressionInMemory.html
https://github.com/ruigege66/JavaScript/blob/master/D20_2_Built-inObject.html
\https://www.cnblogs.com/ruigege0000/