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

What are the types of JavaScript variables and the conversion methods between variables

2025-11-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the "JavaScript variable types and conversion methods between variables" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "JavaScript variable types and conversion methods between variables" article can help you solve the problem.

1. Variable type var num = 10; console.log (typeof num)

Typeof: declare variable types

Alert: pop-up alert box

Prompt: input and output statements

1.1 Color of variable type

Identify variable types according to the color of the console:

Purple: numerical type

Black: character type

Blue: Boolean (true false)

Light gray: undefined null

two。 Literal quantity

A literal is a representation of a fixed value in the source code, that is, a literal representation of how the value is expressed.

3. Data type conversion 3.1. Convert to string type 1. Plus sign concatenation string

Console.log (num+' I am the string')

2.toString () converted to string var num=10;var str=num.toString (); console.log (str); 3.string (variable) 3.2 converted to numeric (key) 1.parseInt (string) function-"integer numeric var age=prompt ('Please enter your age'); console.log (parseInt (age)); console.log (parseInt ('3.14')) / / rounding 3 console.log (parseInt ('3.98')); / / rounding 3 console.log (parseInt (' 120px')); / / rounding 1202.parseFloat (string) function-- "floating-point numeric console.log (parseFloat ('3.14'); console.log (parseFloat (' 120px')); / / 120 removes the px unit 3. Using number (variable) var str='123';console.log (number (str); console.log (number ('123')); 4. Take advantage of arithmetic operations-+ * / implicit conversion console.log ('123mur0); / 12console.log (' 123humor 120'); / 3console.log ('123conversation 1); / 1233.3 convert to Boolean type

Boolean () function

Return value: true or false

False: 0, NaN, null, undefined,''(empty)

Console.log (boolean (')); / / falseconsole.log (boolean (0)); / / falseconsole.log (boolean (NaN)); / / falseconsole.log (boolean (null)); / / falseconsole.log (boolean (undefined)); / / false

The rest are true.

This is the end of the content about "what are the types of JavaScript variables and the conversion methods between variables". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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

  • How to realize css two-column layout based on BFC rules

    This article will explain in detail how to achieve the two-column layout of css based on BFC rules. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

    12
    Report