当前位置: 首页 > news >正文

js面试题2024

  • 1.js的数据类型

boolean number string null undefined bigint symbol object
按存储方式分,前面七种为基本数据类型,存储在栈上,object是引用数据类型,存储在堆上,在栈中存储指针
按es标准分,bigint 和symbol是es6新增的数据类型,bigint存储大整数,symbol解决全局属性名冲突的问题

  • 2.js数据类型检测的方式
typeof 2 //number
typeof true //boolean
typeof 'srt' //string
typeof undefined //undefined
typeof null //object
typeof 1n //bigint
typeof Symbol() //symbol
typeof {} //object
typeof [] //object
typeof function(){} //functionObject.prototype.toString().call()([] instanceof Array)
(function(){} instanceof Function)
({} instanceof Object)
//instanceof只能用于对象,返回布尔值(2).constructor===Number//true(true).constructor===Boolean//true
  • 3.判断数组类型的方式有那些
//1.通过原型判断
const a=[]
const b={}
a instanceof Array
Array.prototype.isPrototypeOf(a)
a.__proto__===Array.prototype
//2.通过object.prototype.tostring.call()
const a=[]
Object.prototype.toString().call(a)
//3.es6的array.isarray()
Array.isArray(a)
  • 4.null和undefined的区别

undefinde代表为定义,变量声明了但未初始化是未定义
null代表空对象,一般用作某些对象变量的初始化值
undefined==void 0
typeof null=object null的地址是0和对象的地址相同

    1. 0.1+0.2!==0.3
// 方法一:放大10倍之后相加在缩小十倍
//方法二:封装浮点数相等的函数
function feg(a,b){return Math.abs(a-b)<Number.EPSILON
}
feg(0.1+0.2,0.3)
  • 6.空类型
[]==false//true
Boolean([])//true
Number([])//0
  • 7.包装类型
const a='abc'
a.length//3
a.toUpperCase()//'ABC'
const c=Object('abc')
const cc=Object('abc').valueOf()
  • 8.new做了什么工作

1.创建了一个新的空对象object
2.将新空对象与构造函数通过原型链连接起来
3.将构造函数中的this绑定到新建的object上并设置为新建对象result
4.返回类型判断

function MyNew(fn,...args){const obj={}obj.__proto__=fn.prototypelet result=fn.apply(obj,args)return result instanceof Object?result:obj
}
function Person(name,age){this.name=namethis.age=age
}
Person.prototype.sayHello=function(){console.log(this.name)
}
const person=MyNew(Person,'test',20)
person.sayHello()
  • 9.继承
//1.原型链继承function Sup(){this.prop='sup'}Sup.prototype.show=function(){}function Sub(){this.prop='sub'}Sub.prototype=new Sup()Sub.prototype.constructor=SubSub.prototype.show=function(){}
//2.构造函数继承function Person(name,age){this.name=namethis.age=age}function Student(name,age,price){Person.call(this,name,age)this.price=price}
//3.原型链加构造函数function Person(name,age){this.name=namethis.age=age}Person.prototype.show=function(){}function Student(name,age,price){Person.call(this,name,age)this.price=price}Student.prototype=new Person()Student.prototype.constructor=PersonStudent.prototype.show=function(){}//4.class extendsclass Animal{constructor(kind){this.kind=kind}}class Cat extends Animal{constructor(kind) {super.constructor(kind);}}
  • 10.深拷贝
    function deep(p,c){let c = c||{}for(let i in p){if(typeof p[i]==='object'){c[i]=p[i].constructor=='Array'?[]:{}deep(p[i],c[i])}else{c[i]=p[i]}}return c}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • tessy 单元测试:小白入门指导手册
  • DAY2:插件学习
  • 【Word】快速对齐目录
  • [Spring] SpringBoot基本配置与快速上手
  • QImage 的图片可以直接显示吗
  • python调用串口收发数据
  • 用WPF实现的窗体是怎么运行的?
  • 反向代理概念
  • app: 和 android:的区别
  • Flutter——最详细(Badge)使用教程
  • 用灵活的依赖排除策略来规避不必要的依赖关系
  • MAVEN中settings.xml文件中,<mirrors> 元素怎么写?
  • 科技赋能智慧应急:“数字孪生+无人机”在防汛救灾中的应用
  • 短视频矩阵系统源码开发-开发思路
  • SVN 80道面试题及参考答案(2万字长文)
  • #Java异常处理
  • $translatePartialLoader加载失败及解决方式
  • 03Go 类型总结
  • 2017-09-12 前端日报
  • HashMap剖析之内部结构
  • Java 内存分配及垃圾回收机制初探
  • JavaScript对象详解
  • JS笔记四:作用域、变量(函数)提升
  • nginx 配置多 域名 + 多 https
  • PhantomJS 安装
  • Python_OOP
  • Python打包系统简单入门
  • Vue.js 移动端适配之 vw 解决方案
  • 函数式编程与面向对象编程[4]:Scala的类型关联Type Alias
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 老板让我十分钟上手nx-admin
  • 聊聊redis的数据结构的应用
  • 前端工程化(Gulp、Webpack)-webpack
  • 终端用户监控:真实用户监控还是模拟监控?
  • #HarmonyOS:软件安装window和mac预览Hello World
  • #NOIP 2014#day.2 T1 无限网络发射器选址
  • $refs 、$nextTic、动态组件、name的使用
  • (1)Hilt的基本概念和使用
  • (2)Java 简介
  • (2)空速传感器
  • (附源码)springboot人体健康检测微信小程序 毕业设计 012142
  • (五)关系数据库标准语言SQL
  • (小白学Java)Java简介和基本配置
  • (原創) 如何動態建立二維陣列(多維陣列)? (.NET) (C#)
  • (转)VC++中ondraw在什么时候调用的
  • .gitignore文件_Git:.gitignore
  • .Net 6.0--通用帮助类--FileHelper
  • .Net程序猿乐Android发展---(10)框架布局FrameLayout
  • /*在DataTable中更新、删除数据*/
  • :中兴通讯为何成功
  • @Data注解的作用
  • @TableLogic注解说明,以及对增删改查的影响
  • [.net]官方水晶报表的使用以演示下载
  • []sim300 GPRS数据收发程序
  • [20160902]rm -rf的惨案.txt