最后
文章到这里就结束了,如果觉得对你有帮助可以点个赞哦
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
引用类型:
常见的值类型:number 、undefined、string、boolean、symbol
常见引用类型:object、array 特殊引用类型:null、fu()函数
2. typeof运算符
// 判断所有值类型 Let a; typeof a // ‘undefined’ const str = ‘abc’; typeof str // ‘string’ const n = 100; typeof n // ‘number’ const b = true; typeof b // ‘boolean’ const s = Symbol( ‘ s ‘); typeof s // ‘symbol’ |
// 能判断函数 typeof console.log // ‘function’ typeof function() {} // ‘function’ |
// 能识别引用类型(不能再继续识别) typeof null // ‘object’ typeof [‘a’, ‘b’] // ’object’ typeof { x: 100 } // ‘object’ |
3. 深拷贝
浅复制
const obj1 = {
age: 20,
name: ‘xxx’,
address: {
city: ‘beijing’
}
}
const obj2 = obj1
obj2.address.city = ‘shanghai’
console.log(obj1.address.city) // shanghai
深复制
const obj1 = {
age: 20,
name: ‘xxx’,
address: {
city: ‘beijing’
},
arr: [‘a’, ‘b’, ‘c’]
}
const obj2 = deepClone(obj1)
obj2.address.city = ‘shanghai’
obj2.arr[0] = ‘a1’
console.log(obj1.address.city) // beijing
console.log(obj1.arr[0]) // a
/**
* 深拷贝
* @param {Object} obj 要拷贝的对象
*/
function deepClone(obj = {}) {
if (typeof obj !== ‘object’ || obj == null) {
// obj 是 null ,或者不是对象和数组,直接返回
return obj
}
// 初始化返回结果
let result
if (obj instanceof Array) { // 判断是否为数组
result = []
} else {
result = {}
}
for (let key in obj) {
// 保证 key 不是原型的属性
if (obj.hasOwnProperty(key)) {
// 递归调用!!!
result[key] = deepClone(obj[key])
}
}
// 返回结果
return result
}
二、变量计算与类型转换
1. 字符串拼接
const a = 100 + 10 // 110 可以使用100 + parseInt(‘10’)
const b = 100 + ‘10’ // 10010
const c = true + ‘10’ // true10
const d = 100 + parseInt(‘10’) // 110
2. 和=
100 == ‘100’ // true
0 == ‘’ // true
0 == false // true
false == ‘’ // true
null == undeined // true
(==尽量尝试让他们变成相等)
// 除了 == null 之外,其他都一律用 ===
Const obj = { x: 100 }
If (obj.a == null ) {}
// 相当于
// if (obj.a === null || obj.a === undefined) {}
3. if语句与逻辑计算
truly变量:!!a === true的变量(经过两次非运算之后为真)
falsely变量: !!a === false的变量(经过两次非运算之后为假)
最后
面试题千万不要死记,一定要自己理解,用自己的方式表达出来,在这里预祝各位成功拿下自己心仪的offer。
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/topics/618166371)**
[外链图片转存中…(img-FKqmvgjC-1715080522083)]
[外链图片转存中…(img-8C1rEa8e-1715080522084)]
[外链图片转存中…(img-UwxlsHx9-1715080522085)]
[外链图片转存中…(img-2mk7oRn9-1715080522086)]