(1)值類型(基本類型):數值(number)、布爾值(boolean)、null、undefined、string(在賦值傳遞中會以引用類型的方式來處理)。 javascript
(2)引用類型:對象、數組、函數。 java
function str()
{
var str1='Hello World';
var str2=str1;
str1='Hello';
alert(str2); //Hello World
}
str();複製代碼
var a = 1;
var b = a;
a ++ ;
console.log(a); // 2
console.log(b); // 1複製代碼
function str()
{
var str1=['Hello World'];
var str2=str1;
alert(str2[0]); //Hello World
str1[0]='Hello';
alert(str2[0]); //Hello
}
str();複製代碼
var a = {}; // a保存了一個空對象的實例
var b = a; // a和b都指向了這個空對象
a.name = 'coco';
console.log(a.name); // 'coco'
console.log(b.name); // 'coco'
b.age = 24;
console.log(b.age);// 24
console.log(a.age);// 24
console.log(a == b);// true複製代碼
var a = 1;
var b = true;
console.log(a == b);//true複製代碼
var a = 'coco';
var b = 'coco';
console.log(a === b);//true複製代碼
var name = 'coco';
var city = 'shenzhen';
var age = 24;複製代碼
var person = {};//建立一個空對象 --引用類型
person.name = 'coco';
person.age = 24;
person.sayName = function(){
console.log(person.name);
}
person.sayName();// 'coco'複製代碼
var person = {};//建立一個空對象 --引用類型
person.name = 'coco';
person.age = 24;
person.sayName = function(){
console.log(person.name);
}
person.sayName();// 'coco'
delete person.name; //刪除person對象的name屬性
person.sayName(); // undefined複製代碼
var person1 = {name:'zhangsan'};
var person2 = {name:'lisi'};
var person3 = {name:'wangwu'};複製代碼
var person1 = '{}';
var person2 = '{}';
console.log(person1 == person2); // true複製代碼
var person1 = {};
var person2 = {};
console.log(person1 == person2); // false複製代碼