当前位置:网站首页>Number() VS parseInt()
Number() VS parseInt()
2022-07-26 20:31:00 【紫微前端】
两者Number()和parseInt()通常用于将字符串转换为数字。
差异
Number()转换类型,而 parseInt 解析输入的值。
// Parsing
parseInt('32px'); // 32
parseInt('5e1'); // 5
// Convert type
Number('32px'); // NaN
Number('5e1'); // 50- 如您所见,
parseInt将解析到第一个非数字字符。另一方面,Number会尝试转换整个字符串。 parseInt接受两个参数。第二个参数用于表示基数。
parseInt('0101'); // 101
parseInt('0101', 10); // 101
parseInt('0101', 2); // 5
Number('0101'); // 101当我们传递特殊值时,它们会返回不同的结果,例如undefinedor null:
边栏推荐
- 修改excel默认编码
- Practice of microservice in solving Library Download business problems
- Basic use of livedatade
- conda报错:json.decoder.JSONDecodeError:
- [hcie security] dual computer hot standby - primary and standby backup
- Devsecops, speed and security
- [virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure
- Error in render: “TypeError: data.slice is not a function“
- Leetcode hash table class
- There are six ways to help you deal with the simpledateformat class, which is not a thread safety problem
猜你喜欢

Leetcode linked list problem - 19. Delete the penultimate node of the linked list (learn the linked list with one question and one article)

The hardest lesson we learned from the crypto Market

GOM and GEE lander list file encryption tutorial

After chatting with byte programmers with a monthly salary of 3W, I realized that I had been doing chores

Detailed illustration of B-tree and its implementation in C language

Error in render: “TypeError: data.slice is not a function“

How to use multiple languages in a project?

Some unexpected bug records
Monitor MySQL based on MySQL exporter

Live broadcast appointment award | senior consultant xuyanfei: how does efficiency measurement help efficient and sophisticated outsourcing management
随机推荐
Leetcode linked list problem -- 24. Exchange the nodes in the linked list in pairs (learn the linked list with one question and one article)
25张炫酷交互图表,一文入门Plotly
CFdiv1+2-Pathwalks-(树状数组+线性dp)
【HCIA安全】双向NAT
Svn uses fragmented ideas
The hardest lesson we learned from the crypto Market
苹果官网罕见打折,iPhone13全系优惠600元;国际象棋机器人弄伤对弈儿童手指;国内Go语言爱好者发起新编程语言|极客头条
[hero planet July training leetcode problem solving daily] 26th and check the collection
[MySQL series] - how much do you know about the index
Broadcast voice H5 speechsynthesisutterance
功能尝鲜 | 解密 Doris 复杂数据类型 ARRAY
Serial port communication failure
Live broadcast appointment award | senior consultant xuyanfei: how does efficiency measurement help efficient and sophisticated outsourcing management
kubernetes之Deployment
There are six ways to help you deal with the simpledateformat class, which is not a thread safety problem
我们从Crypto市场中学到的最艰难一课
idea中debug时如何进入指定的用户方法体中?
[virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure
HTTP cache browser cache that rabbits can understand
Custom annotation (I)