当前位置:网站首页>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
边栏推荐
- tensorrt yolov5_ trt. Py comments
- 【pytorch】nn.AdaptiveMaxPool2d
- I use flask to write the website "one"
- Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
- 队列的实现和应用
- The fixed assets management system enables enterprises to dynamically master assets
- 2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于物联网的GY906红外测温门禁刷卡系统
- Shell script case in and regular expressions
- JCL 和 SLF4J
猜你喜欢

dsPIC30F6014a LCD 方块显示

【pytorch】2.4 卷积函数 nn.conv2d

樹結構---二叉樹2非遞歸遍曆

【电赛训练】红外光通信装置 2013年电赛真题

【pytorch】nn. Crossentropyloss() and nn NLLLoss()

Mise en œuvre simple de l'équilibrage de la charge par nacos

Simple load balancing with Nacos
![[pytorch] 2.4 convolution function nn conv2d](/img/eb/382a00af5f88d5954f10ea76343d6e.png)
[pytorch] 2.4 convolution function nn conv2d

nacos簡易實現負載均衡

Installing Oracle EE
随机推荐
Implementation and application of queue
Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
Shell script - definition, assignment and deletion of variables
How to solve the problem of fixed assets management and inventory?
PR training notes
LogBack
通过 代码实例 理解 浅复制 与 深复制
LogBack
树结构---二叉树1
JCL 和 SLF4J
3D打印Arduino 四轴飞行器
TV size and viewing distance
[interview brush 101] linked list
[ESP nanny level tutorial] crazy completion chapter - Case: chemical environment system detection based on Alibaba cloud and Arduino, supporting nail robot alarm
Understanding and implementation of AVL tree
Log4j 日志框架
pcl_viewer命令
OSPF - virtual link details (including configuration commands)
2.4 activation function
Shell script - positional parameters (command line parameters)