当前位置:网站首页>js valueOf 与 toString 区别
js valueOf 与 toString 区别
2022-07-01 09:13:00 【su27_0101】
- valueOf 返回对象本身、
- toString 返回对象描述字符串
obj = new Object(); // {}
obj.toString(); // '[object Object]'
obj.valueOf() == obj // true
toString是把对象转换为字符串;
valueOf是把对象转换成一个基本数据的值
valueOf偏向于运算,toString偏向于显示。
1、 在进行对象转换时(例如:alert(a)),将优先调用toString方法,如若没有重写toString将调用valueOf方法,如果两方法都没有重写,按Object的toString输出。
2、 在进行强转字符串类型时将优先调用toString方法,强转为数字时优先调用valueOf。
3、 在有运算操作符的情况下,valueOf的优先级高于toStri
边栏推荐
- Shell脚本-变量的定义、赋值和删除
- LogBack
- Redis source code learning (29), compressed list learning, ziplist C (II)
- [pytorch learning] torch device
- I use flask to write the website "one"
- 序列化、监听、自定义注解
- R language observation log (part24) -- initialization settings
- Class loading
- tensorrt yolov5_ trt. Py comments
- pcl_viewer命令
猜你喜欢

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
![[video game training] real topic of 2013 video game of infrared optical communication device](/img/ef/c2c45c1c6c24aed0a4e93101047372.png)
[video game training] real topic of 2013 video game of infrared optical communication device

Principles of Microcomputer - Introduction

3D printing Arduino four axis aircraft

dsPIC30F6014a LCD 方块显示

【pytorch】softmax函数

NiO zero copy

钓鱼识别app

Redis -- lattice connects to redis cluster

【检测技术课案】简易数显电子秤的设计与制作
随机推荐
Class loading
Understanding and implementation of AVL tree
Meituan machine test in 2022
美团2022年机试
[pytorch learning] torch device
队列的实现和应用
Implementation and application of queue
Personal decoration notes
Jetson Nano 安装TensorFlow GPU及问题解决
How to effectively align team cognition
序列化、监听、自定义注解
MySQL optimization
Input标签的type设置为number,去掉上下箭头
[video game training] real topic of 2013 video game of infrared optical communication device
【pytorch】transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
Naoqi robot summary 28
钓鱼识别app
Databinding source code analysis
NoSQL数据库的安装和使用
Football and basketball game score live broadcast platform source code /app development and construction project