Home  >  Article  >  Web Front-end  >  JS data types

JS data types

不言
不言Original
2018-04-10 11:21:151385browse

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


Basic data types


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)转义字符

1. Numeric type

In JS , all numbers are represented by floating point types

1. Integer data

The data structure is a decimal integer, which can be a positive number, a negative number or 0

2. Floating Point data

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

2. String type

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.

1. One or more characters enclosed in single quotes
'我'
'我们'
2. One or more characters enclosed in double quotes
"我们"
"咦"
3. Delimited by single quotes The string delimited by double quotes can contain double quotes
'我是"XXX"'
4. The string delimited by double quotes can contain single quotes
"您看可以'……'"

Application: In script
var str1="";
var str2="";
......
document.write(str1+"< br/>");
document.write(str2+"< br/>");

3. Boolean type

The Boolean data types are only: true (true) and false (false), 0 can be regarded as false, 1 can be regarded as true

Special Data type

JS特殊数据类型:
(1)空值(null型)
(2)未定义值(undefined型)
(3)转义字符

1. Null value

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

2. Undefined value

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.

3. Escape characters

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

Basic data type

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)转义字符

1. Numeric type

In JS, all numbers are represented by floating point types

1. Integer data

The data structure is Decimal integer, which can be a positive number, a negative number or 0

2, floating point data

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

2. String type

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
'我'
'我们'
2. One or more characters enclosed in double quotes
"我们"
"咦"
3. In a string delimited by single quotes Can contain double quotes
'我是"XXX"'
4. Strings delimited by double quotes can contain single quotes
"您看可以'……'"
Application: In script

var str1=”“;
var str2="";
......
document.write(str1+"< br/>");
document.write(str2+"< br/>");

3. Boolean type

Boolean data types are only: true (true) and false (false), 0 can be regarded as false, 1 can be regarded as true

Special data type

JS特殊数据类型:
(1)空值(null型)
(2)未定义值(undefined型)
(3)转义字符

1. Null value

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

2. Undefined value

If a variable has been declared with the var keyword, but the variable has not been assigned a value, and the variable cannot be known data type, 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.

3. Escape characters

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn