In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge of what is the difference between parseInt () and Number () in JS. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Learning content:
The parseInt () function parses the given string to an integer at the specified cardinality. The second parameter of parseInt (string,radix) indicates the base used, which we usually use as base 10, or as far as 8 or 16. In order to avoid errors in parsing strings starting with "0" and "0x", various javascript programming specifications stipulate that the value of the second parameter must be clearly given, such as parseInt ("123,10).
ParseInt ('16, 8) = 14parseInt ('10, 8) = 8parseInt ('16, 10) = 16parseInt ('10, 10) = 10parseInt ('16, 16) = 22parseInt ('10, 16) = 16
ParseInt parses string to an integer from scratch, returns the part of the integer that has been parsed when it encounters a character that cannot be parsed, and returns NaN directly if the first character cannot be parsed.
Number () can be used to perform type conversions when the new operator is not used. If it cannot be converted to a number, NaN is returned. Like "123a", parseInt () returns 123 number () and NaN, and different types of strings use the conversion difference between the two functions:
/ / when the string is made up of numbers, there is no difference between the numbers they convert let numStr = '123'console.log (parseInt (numStr)) / / 123console.log (Number (numStr)) / / 123 let numStr / when the string is made up of letters let numStr =' abc'console.log (parseInt (numStr)) / / NaNconsole.log (Number (numStr) / / NaN// when the string is composed of numbers and letters, let numStr = '123a'console.log (parseInt (numStr)) / / 123console.log (Number (numStr)) / / NaN// when the string is composed of 0 and the number let numStr =' 0123'console.log (parseInt (numStr)) / / 123console.log (Number (numStr)) / / 123 * * when the character The string contains the decimal point * * let numStr = '123.456'console.log (parseInt (numStr)) / / 123console.log (Number (numStr)) / / 123.456 / * when the string is null * * let numStr = nullconsole.log (parseInt (numStr)) / / NaNconsole.log (Number (numStr)) / / 0 / * When the string is''(empty), * * let numStr =''console.log (parseInt (numStr)) / / NaNconsole.log (Number (numStr)) / / 0 is all the content of the article "what's the difference between parseInt () and Number () in JS?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.