当前位置:网站首页>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
边栏推荐
- [ESP nanny level tutorial] crazy completion chapter - Case: chemical environment system detection based on Alibaba cloud and Arduino, supporting nail robot alarm
- How to manage fixed assets efficiently in one stop?
- [pytorch learning] torch device
- 【检测技术课案】简易数显电子秤的设计与制作
- 序列化、监听、自定义注解
- Shell脚本-while循环详解
- 类加载
- Class loading
- Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
- MapReduce编程基础
猜你喜欢

PR training notes

Pain points and solutions of fixed assets management of group companies

Which method is good for the management of fixed assets of small and medium-sized enterprises?

Why is the Ltd independent station a Web3.0 website!

How to launch circle of friends marketing and wechat group activities

足球篮球体育比赛比分直播平台源码/app开发建设项目

钓鱼识别app

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)

TV size and viewing distance

Principle and application of single chip microcomputer timer, serial communication and interrupt system
随机推荐
Installing Oracle EE
Interrupt sharing variables with other functions and protection of critical resources
Shell script case in statement
[ESP nanny level tutorial] crazy completion chapter - Case: gy906 infrared temperature measurement access card swiping system based on the Internet of things
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
pcl_viewer命令
【检测技术课案】简易数显电子秤的设计与制作
SDN_ Simple summary
Mise en œuvre simple de l'équilibrage de la charge par nacos
Imitation of Baidu search results top navigation bar effect
Promise asynchronous programming
Databinding source code analysis
Shell脚本-read命令:读取从键盘输入的数据
Shell script -if else statement
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
Can diffusion models be regarded as an autoencoder?
How to manage fixed assets well? Easy to point and move to provide intelligent solutions
TV size and viewing distance
【pytorch】2.4 卷积函数 nn.conv2d
树结构---二叉树1