多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## JS基础课阶段复习 ### 一、基础知识问答 #### 1. JS中的数据类型包括: * 基本数据类型 * number * string * boolean * null * undefined * symbol * bigint * 引用数据类型 * object * {} 普通对象 * [] 数组对象 * /^$/ 正则对象 * Math * 日期对象 * … * function > 基本数据类型是按照值操作,直接把值存储到栈内存中即可;引用数据类型的值是存储到堆内存中的,我们操作的都是堆内存的引用地址; #### 2. JS中检测数据类型: * typeof * instanceof * constructor * Object.prototype.toString.call() #### 3. 浏览器常用的内核: * webkit * gecko * trident * blink #### 4. JS中创建变量的几种常用方式: * var * let / const * function * class * import #### 5. null和undefined的区别: #### 6. ~~~ let n = { name:'珠峰培训' }; let m = n; n.teacher = n = { name:'周啸天' }; m.teacher = { name:'耿银鹏' }; console.log(m.name); //“珠峰培训” console.log(n.name); // “周啸天” console.log(m.teacher.name); // “耿银鹏” console.log(n.teacher.name); // 报错 Uncaught TypeError: Cannot read property 'name' of undefined ~~~ ![](https://img.kancloud.cn/c7/79/c779486f0632d017c0e61ec3e4ab9c3f_1978x1038.png) #### 7. ‘number’ ~~~javascript let num = Number('12.5px'); //=>NaN let type = typeof num; //=>"number" if (num == NaN) { alert(NaN); } else if (type === 'number') { alert('number'); } else if (num == 12.5) { alert(12.5); } else { alert('12.5px'); } ~~~ #### 8. ``` console.log(1 + false + undefined + [] + null + true + '珠峰培训' + [12]+ 1); let i=1; console.log(2-(i++)+(--i)+2+(++i)-(i--)-2); console.log(i); ``` “NaNnulltrue珠峰培训121” 2 1 ~~~javascript //=>加号在JS中除了数学运算还有字符串拼接(加号左右两边出现字符串或者对象,基本上都是字符串拼接) console.log(1 + false + undefined + [] + null + true + '珠峰培训' + [12] + 1); /* 1 + false -> 1 1 + undefined -> NaN *** NaN + [] -> 'NaN' *** 'NaN' + null -> 'NaNnull' ...字符串拼接 */ /* * 不论 i++ 还是 ++i,都是在自身基础上累加1的数学运算 * => 和 i+=1 或者 i=i+1 还不是完全一致的 * => i++是先运算,后自身累加1,而++i是先自身累加1,然后再去运算的(不论是否加了小括号) */ let i=1; console.log(2-(i++)+(--i)+2+(++i)-(i--)-2); console.log(i); /* 2-(i++) => 2-i / i++ => 1 i=2 1+(--i) => --i / 1+累减结果 => i=1 2 2+2 => 4 4+(++i) => ++i / 4+累加结果 => i=2 6 6-(i--) => 6-i / i-- => 4 i=1 4-2 => 2 i=1 */ //let n="10"; //n++ => 11 //n+=1 => "101" //n=n+1 => "101" ~~~ ![](https://img.kancloud.cn/f2/0e/f20e0f693b836cf2ef7936e3b040d036_556x68.png) #### 9. “1” “0” ~~~javascript //=>alert输出的结构都是转换为字符串的 for (var i = 10; i >= 2; i--) { if (i === 6) { i-=2; break; } else if(i<=5) { i=2; } else { i-=2; continue; } i--; alert(i); } alert(i); ~~~ #### 10. ~~~javascript Number(""); //=>0 parseFloat(""); //=>NaN !!"parseInt(NaN)"; //=>把非空字符串转化为布尔 true !typeof typeof typeof [12,23]; //=>false /* typeof typeof typeof [12,23] => "string" !"string" => false */ parseFloat("1.6px") + parseInt("1.2px"); /* parseFloat("1.6px") => 1.6 parseInt("1.2px") => 1 1.6 + 1 => 2.6 */ typeof "parseInt(undefined)" + 12 + !!Number(''); /* typeof "parseInt(undefined)" => "string" !!Number('') => false "string" + 12 + false => "string12false" */ typeof !!parseInt(undefined) + !parseFloat(null); /* typeof !!parseInt(undefined) parseInt(undefined) => parseInt("undefined") => NaN !!NaN => false typeof false => "boolean" !parseFloat(null) parseFloat(null) => NaN !NaN => true "boolean" + true => "booleantrue" */ ~~~