Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of javascript basic data Type conversion

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article shares with you the content of a sample analysis of javascript basic data type conversion. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Case toString () converts to string var num = 1; alert (num.toString ()); String () converts to string var num = 1; alert (String (num)); the result of plus sign concatenation and string concatenation is string var num = 1; alert (num + "I am a string"); / / 1. Convert numeric type to string type var num = 10; var str = num.toString () var str1 = num+'' console.log (str); console.log (typeof str); / / typeof js to view the data type console.log (String (num)); console.log (typeof String (num)); / / string console.log (str1); console.log (typeof str1)

String type conversion to numeric description case parselnt (string) function converts string type to integer numeric parselnt ('15') parseFloat (string) function converts string type to floating point numeric parseFloat (' 3.14') Number () forced conversion function converts string type to numeric Number ('12') js implicit conversion (- * /) implicit conversion to numeric' 12'-0big / 2 using arithmetic operations. Convert a string to a numeric type / / parseInt () console.log (parseInt ('15')); / / 15 console.log (typeof parseInt (' 15')); / / number console.log (parseInt ('3.14')); / / 3 console.log (parseInt (' 3.94')); / / 3 console.log (parseInt (3.94)); / 3 take the integer portion of a floating point number

/ / parseFloat console.log (parseFloat ('3.14')); / / 3.14 console.log (parseFloat (' 3')); / / 3Accord / number console.log (Number ('12')); / / 12 console.log (typeof Number (' 12')); / / number

/ / using arithmetic-* / implicit conversion console.log ('12'-0); / / 12 console.log (' 123-'120'); / / 3 console.log (' 123 calendar 1); / 123 console.log ('123 impulse 1); / / 123

Conversion to Boolean shows that the case Boolean () function converts other types to Boolean Boolean ('aniu')

Values that represent null and negative are converted to false, such as'', 0, NaN, null, undefined.

The rest of the values are converted to true.

Console.log (Boolean (')); / false console.log (Boolean ('')); / / true console.log (Boolean (0)); / / false console.log (Boolean (NaN)); / / false console.log (Boolean (null)); / / false console.log (Boolean (undefined)); / / false console.log (Boolean ('aniu')); / / true console.log (Boolean (15)); / / true

Thank you for reading! This is the end of this article on "sample analysis of javascript basic data type conversion". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report