review0601
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>查漏补缺</title></head><body></body> <script type="text/javascript"> // var a; // 什么是变量 // 数据:4 'str' true {} [] // 一次:哪里需要写哪里 // 多次:保存数据的容器 // 1、什么是标识符 // 变量、函数、属性的名字,或者函数的参数 // 2、标识符的命名规则 // -由字母,数字,下划线(_)或美元$组成 // -不能以数字开头 // -不能使用关键字,保留字作为标识符 // var nun = 4;num NUM 严格区分大小写 // 关键字:if for // 保留字:class // 基本数据:4 'str' true undefined null // 引用数据:[]数组 {}对象 // 区别: // 1、基本数据类型值不可以修改 // 2、引用数据类型值可以修改 // var num = 4; // num = 3;//覆盖 // var str = 'string'; // var anotherStr = str.replace('s',''); // console.log(str+"|"+anotherStr); // var person = {}; // console.log(person); // //var str = 'xiao ming'; // person.name='xiao ming'; // person.sex='male'; // person.sex='female'; // person.family=['ming ba','ming ma']; // delete person.sex; // console.log(person); // var person = 'person'; // person.name='xiao ming'; // console.log(person.name);// // var str = 'string';//包装类 -- 才可以调用replace方法 // var anotherStr = str.replace('s',''); // console.log(str+"|"+anotherStr); // 1 -- Number // 'str' -- String // 数据到底保存在哪里? -- 堆栈 // 1、堆内存 // 空间大小不固定 -- 别墅 // 2、栈内存 // 有序排列的,会分成一个一个小房间,每一个小房间是存储变量的, // 但是栈内存每一个大小都是固定的,不能扩建 -- 公寓式 // var xmScore = 4; // var xhScore = 4; // console.log(xmScore === xhScore); // var xm={ // age:18, // score:4 // }; // var xh={ // age:18, // score:4 // }; // console.log(xm === xh); // var xm={ // age:18, // score:4 // }; // var xh = xm; // console.log(xm === xh); //需求: // var xm={ // age:18, // score:4, // str:'ss' // }; // var xh={ // score:4, // age:18 // }; // // console.log(xm === xh); // function equalObjs(a,b){//a和b 就是对象 // console.log(a); // console.log(b); // for(var p in a){ // console.log(a[p]+"-"+p); // console.log(b[p]+"-"+p); // if (a[p]!==b[p]) {return false;} // } // return true; // } // console.log(equalObjs(xm,xh)); // function equalsArrays(a,b){ // if (a.length!=b.length) {return false;} // for(var i=0;i<a.length;i++){ // if (a[i]!==b[i]) {return false;} // } // return true; // } // //复制 // var xmscore = 4; // var xhscore = xmscore; // xhscore++; // console.log(xhscore);//5 // // console.log(xmscore);//4 基本数据类型的值互不干涉 // var xm={ // age:18, // score:4 // }; // var xh = xm; // console.log(xh.score);//4 // xh.score++; // console.log(xh.score);//5 // console.log(xm.score);//5 因为他们同时指向一个引用 // var xm={ // age:18, // score:4 // }; // function copyObj(obj){ // var newObj={}; // for(var p in obj){ // newObj[p]=obj[p]; // } // return newObj; // } // xh=copyObj(xm); // console.log(xh); // console.log(xh === xm); //参数传递 // function fn(a,b){//形参 // return a+b; // } // fn(1,2);//实参 // function addTen(num){ // return num+10; // } // var score = 10; // console.log(addTen(score)); // function setName(obj){ // return obj.name="xm"; // } // var person={}; // setName(person); // console.log(person.name);//xm // obj=person//他们指向同一个地址 //检测 // 4 // 'string' // true // undefined // null // [] // {} // function // RegExp //typeof m typeof(m) // console.log(typeof 4); // console.log(typeof(4)); // console.log(typeof 'string'); // console.log(typeof true); // console.log(typeof undefined); // console.log(typeof null); // console.log(typeof []); // console.log(typeof {}); // console.log(typeof function(){}); // console.log(typeof /a/); // console.log(typeof Array); // //instanceof 表示前面是否是后面的实例 // console.log([] instanceof Array); // console.log([] instanceof Object); // console.log({} instanceof Object); // console.log({} instanceof Array); // //instanceof不能和基本数据类型一起使用 // console.log(1 instanceof Number); // 变量的 // 作用:起作用 // 域:区域和范围 // 1、变量的生命周期 // 2、访问到变量 // 作用域 // 全局作用域 // 局部作用域:函数作用域 // var name = 'xm'; // function fn(argument){ // var sex = 'male'; // } // console.log(sex); // fn();//xm // var name; // console.log(name); // var name = 'm'; // var age = 18;x // function fn(){ // // var name; // console.log(name);//undefined js的预解析机制 // var name = 'xh'; // var age = 10; // } // fn();//xh // console.log(a); // var a = 1; 变量提升 // console.log(a); // console.log(a);//undefined // a = 1; // console.log(a);//1 // console.log(a); // a = 1;//报错 // var a = 1;//全局变量 // var a = 1; // function fn(){ // console.log(a);//undefined // var a = 2; // } // fn(); // console.log(a);//1 // var a = 1; // function fn(){ // console.log(a);//1 这里的fn作用域中没有找到var定义 所以只能往外找,所以输出第一个a = 1 // a = 2;//由于他没有var定义,所以这里的a是全局变量 覆盖 // } // fn(); // console.log(a);//2 // var a = 1; // function fn(a){//fn作用域中的局部变量 var a; // console.log(a);//undefined 预解析 // a = 2;//这里的a修改局部变量 // console.log(a); // } // fn(); // console.log(a);//1 // var a = 1; // function fn(a){ // console.log(a);//1 // var a = 2;//这里的a修改局部变量 // } // fn(a);//读取的是全局a所以第一个a输出1 // console.log(a);//1 </script> <!-- <script type="text/javascript"> console.log(a);//1 </script> --></html>