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

JavaScript 小测验 toString

toString方法

以下console.log会输出什么?

const obj = {}
const fun = () => {}
console.log(obj.toString === Object.toString)
console.log(fun.toString === Function.toString)
console.log(obj.toString === Object.prototype.toString)
console.log(fun.toString === Function.prototype.toString)
console.log(Object.toString === Object.prototype.toString)
console.log(Function.toString === Function.prototype.toString)

答案

 // 创建一个空对象
const obj = {}
// 创建一个空的箭头函数
const fun = () => {}

// 检查obj的toString方法是否等于Object的toString方法,预期为false
console.log(obj.toString === Object.toString)

// 检查fun的toString方法是否等于Function的toString方法,预期为true
console.log(fun.toString === Function.toString)

// 检查obj的toString方法是否等于Object.prototype上的toString方法,预期为true
console.log(obj.toString === Object.prototype.toString)

// 检查fun的toString方法是否等于Function.prototype上的toString方法,预期为true
console.log(fun.toString === Function.prototype.toString)

// 检查Object的toString方法是否等于Object.prototype上的toString方法,预期为false
console.log(Object.toString === Object.prototype.toString)

// 检查Function的toString方法是否等于Function.prototype上的toString方法,预期为true
console.log(Function.toString === Function.prototype.toString)


http://www.kler.cn/news/284041.html

相关文章:

  • 无人机之使用技巧篇
  • Tomcat Manager 上传 war 包大小的限制
  • SpringBoot配置MybatisPlus
  • Docker基本使用:根据mysql镜像创建mysql容器
  • 四、监控搭建-Prometheus-采集端批量部署
  • TCP/UDP的对比,粘包分包抓包,http协议
  • MYSQL集群技术
  • JavaScript 网页设计案例
  • 12、stm32通过dht11读取温湿度
  • Elasticsearch简单介绍
  • 智慧高校迎新服务平台的设计与实现---附源码92489
  • http方法调用接口
  • Django如何实现websocket
  • 【工作实践】MVEL 2.x语法指南
  • vscode在html中的使用
  • 多进程比多线程开销大的原因
  • 海绵城市雨水监测系统
  • C++:Github开源7.8Kstar的线程池介绍
  • 如何在没有密码的情况下解锁 Oppo 手机?5 种简单的方法
  • hadoop日志文件
  • 随身wifi靠谱吗?适合哪类人使用?靠谱随身wifi怎么选?热门随身wifi推荐测评!
  • CRC32
  • 使用[KafkaStreams流计算框架实时计算产生报警(升级报警)
  • 深入解析Nginx的Fair调度算法:实现请求的智能分配
  • 中国各地区数字经济发展对环境污染的影响数据(2011-2021年)
  • 坐牢第三十天(c++)
  • 【微信小程序】分包--独立分包
  • 请问基于规则和强化学习的各自的优缺点有哪些?应用场景有哪些?今天的北京机器人展上的技术专家的技术
  • 学习日志30
  • 鸿蒙( Beta5.0版)开发实战:自定义TabBar页签