2024年最新快速搞定前端JS面试 -- 第二章 JS基础-变量类型和计算,腾讯团队实力打造flutter入门教程

最后

文章到这里就结束了,如果觉得对你有帮助可以点个赞哦

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

引用类型:

常见的值类型: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)]

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值