How to use JavaScript’s basic data types?

Data types in JavaScript are divided into two major categories, namely basic data types and complex data types (or reference data types), as shown in the figure.
1682069412230_data type.png

This section focuses on basic data types. Below we use code to demonstrate the use of basic data types.

(1) Number type (Number), including integer values ​​and floating point values:

var numl = 21;                          //整型值 
var num2 = 0.21;                         //浮点型值

(2) Boolean type (Boolean), including two Boolean values ​​of true and false:

var booll = true;                  //表示真、1、成立
var bool2 = false;                 // 表示假、0、不成立

(3) String type (String), wrapped in single quotes or double quotes:

var strl = '';                    //空字符串
var str2 = 'abc';                 //单引号包裹的字符串 abc
var str3 = "abc";                 //双引号包裹的字符串 abc

(4) Undefined type (Undefined), there is only one value undefined:

var a;                           // 声明变量 a,未赋值,此时 a就是undefined
var b = undefined;               //变量b的值为 undefined

(5) Stereotype (Null), there is only one value null:

var a = null;                   //变量a的值为nu11

It should be noted that the values ​​tue, false, undefined and null in the code must all be written in lowercase letters.

Supongo que te gusta

Origin blog.csdn.net/cz_00001/article/details/132884867
Recomendado
Clasificación