The content introduced in this article is the data type of JS. I will share it with you here. Friends in need can refer to it
JavaScript data types have two major categories: one is "basic data type" and the other is "special data type".
Among them, the basic data types include the following three types:
(1)数字型(Number型) (2)字符串型(String型) (3)布尔型(Boolean型)
There are three special data types:
(1)空值(null型) (2)未定义值(undefined型) (3)转义字符
In JS , all numbers are represented by floating point types
The data structure is a decimal integer, which can be a positive number, a negative number or 0
Data with decimals
Floating point numbers can also use the exponential method, that is, a real number followed by e or E, followed by a plus or minus sign, and then an integer exponent. The value represented by this counting method is equal to the previous real number multiplied by the exponential power of 10
A string is a sequence composed of Unicode characters, numbers, punctuation marks, etc. , is the data type used by JS to represent text, contained in single quotes or double quotes, and the quotes can contain another type of quotes.
'我' '我们'
"我们" "咦"
'我是"XXX"'
"您看可以'……'"
Application: In script
var str1="";
var str2="";
......
document.write(str1+"< br/>");
document.write(str2+"< br/>");
The Boolean data types are only: true (true) and false (false), 0 can be regarded as false, 1 can be regarded as true
JS特殊数据类型: (1)空值(null型) (2)未定义值(undefined型) (3)转义字符
The system does not allocate memory space for null value
null is not equal to the empty string ("") or 0, because the empty string or 0 exists, but null means it does not exist
If a variable has been declared with the var keyword, but the variable has not been assigned a value, and There is no way to know the data type of this variable, so the data type of this variable is undefined, indicating that this is a variable of undefined data type.
In addition, there is a special type of numeric constant NaN in JavaScript, which is "not a number". When a calculation error occurs in the program for some reason, a meaningless number will be generated. At this time, the numerical value returned by JavaScript is NaN.
The difference between null and undefined is that null means that a variable has been assigned a null value, while undefined means that the variable has not yet been assigned a value.
Escape characters Description
\b Backspace
\n Enter and line feed
\t Tab symbol
\f Page change
\' Single quote
\” Double quote
\v Tab (Tab, horizontal)
\r Line feed
\ Backslash
\OOO Octal integer, range is 000 ~777
\xHH Hexadecimal integer, ranging from 00~FF
\uhhhh Hexadecimal encoded Unicode character
JavaScript data types are 2 major categories: one is "basic data types" and the other is "special data types"
Among them, basic data types include the following three types:
(1)数字型(Number型) (2)字符串型(String型) (3)布尔型(Boolean型)
There are three special data types:
(1)空值(null型) (2)未定义值(undefined型) (3)转义字符
In JS, all numbers are represented by floating point types
The data structure is Decimal integer, which can be a positive number, a negative number or 0
Data with decimals
Floating point numbers can also use the exponential method, that is, a real number followed by e or E, followed by a positive and negative sign, followed by an integer exponent. The value represented by this counting method is equal to the previous real number multiplied by the power of 10
A string is a sequence composed of Unicode characters, numbers, punctuation marks, etc. It is a data type used by JS to represent text. It is contained in single quotes or double quotes. The quotes can contain another type of quotes
#. ##1. One or more characters enclosed in single quotes'我' '我们'
"我们" "咦"
'我是"XXX"'
"您看可以'……'"
var str1=”“;
var str2="";
......
document.write(str1+"< br/>");
document.write(str2+"< br/>");
JS特殊数据类型: (1)空值(null型) (2)未定义值(undefined型) (3)转义字符
null is not equal to the empty string ("") or 0, because the empty string or 0 exists , but null means it does not exist
In addition, there is a special type of numeric constant NaN in JavaScript, which is "not a number". When a calculation error occurs in the program for some reason, a meaningless number will be generated. At this time, the numerical value returned by JavaScript is NaN.
The difference between null and undefined is that null means that a variable has been assigned a null value, while undefined means that the variable has not yet been assigned a value.
Escape characters Description
\b Backspace
\n Enter and line feed
\t Tab symbol
\f Page change
\' Single quote
\” Double quote
\v Tab (Tab, horizontal)
\r Line feed
\ Backslash
\OOO Octal integer, range is 000 ~777
\xHH Hexadecimal integer, ranging from 00~FF
\uhhhh Hexadecimal encoded Unicode character
Related recommendations:
In-depth Understanding js data types
Detailed explanation of js data types
Sharing of seven js data types
The above is the detailed content of JS data types. For more information, please follow other related articles on the PHP Chinese website!