JavaScript Development Technology Encyclopedia-3rd Chapter JS Data type _ basic knowledge

Source: Internet
Author: User
Tags numeric
3.1 Basic data types
1. String type: Consists of Unicode characters, numbers, punctuation marks, no char character type in JavaScript, even if only one character, must be used
2 digit (number): does not distinguish between integral and floating-point types
3. Booleans (Boolean)
3.2 Composite data types
1. Array: Array elements: The data placed in an array is called an array element.
Array subscript: Numbering starting from 0
READ: Arr[0];
Assign value: arr[1]=120;
2. Objects:
The name of the object. Property name
Object name. Method Name ()
3.3 Other data types
Function:
A function in 1.javascript is a data type, so it can be stored in a variable, array, or object.
2 null: In JavaScript, NULL is a standalone data type that represents no value
3.undefined is undefined meaning, there are 4 kinds of cases will return to undefined.
A. Define a variable, but not yet assigned a value.
B. Use of an undefined variable
C. Defines an object property that does not exist
D. A reference to an array element that does not exist.
3.4 Conversion of data types
Principle: Converts a data type to the type of data that is required in the current environment.
JavaScript data type implicit conversion rules
1. Implicit conversions of data types:
Original data type The data type of the target ticket Description
String Non-empty string Digital Lane

If the character in the string is a number, the number converted to a string, such as "123" converts to a number of 123,

If the character in the string is not a pure number, it is converted to NAA

Boolean type True
Empty character Digital type 0
Boolean type Flase
String "true" Digital type Nan
Boolean type True
Field character string "Flase" Digital type Nan
Boolean type True
Digital type General numbers String Can convert a number to a string "number"
Boolean type Convert number 0 to false, other numbers to true
Nan String type Convert to String "Nan"
Boolean type Convert to False
Boolean type True String type Convert to String "true"
Digital type Convert to 1
False String type Convert to String "false"
Digital rationale Convert to 0
Null String type Convert to string "null"
Digital type Convert to 0
Boolean type Convert to False
Undefined String type Convert to string "undefined"
Digital type Convert to Nan
Boolean type Convert to False

2. Implicit conversion of alternative data

3. Display conversions for data types

1. Convert to Digital type

。 Nubmer (value) converts value to an integer or floating-point number

。 parseint (value) converts value to an integer

。 Parseflaot (value) to float

cannot be converted to a numeric type, will return Nan

Conversion rules that convert other types to numeric

td> description
data type
string empty string use number () to convert to 0, using parseint () and parsefloat () Convert to Nan
string "ture" to nan
string "False " to Nan
Other strings

If the character in the string is a number, convert the number in the character, such as the string "123"

to the number 123. If the string is not a pure number, it is converted to Nan

true uses the numbers () conversion to 0, using the Parsei NT () and parsefloat () convert to Nan
false use number () to convert to 0, using parseint () and parsefloat () to NAN
null converts to 0 using number () and parseint () and parsefloat () to Nan
undefined convert to nan

2. Convert to Boolean

To convert another data type to a Boolean

    ;                      data type language
string empty string convert to false
string "True" convert to True
string "flase" convert to TRUE
other string convert to True
digital 0 convert to False
Nan converts to False
Other numbers convert to True
null convert to False
undefined convert to False

3. Convert to String type

To convert another data type to a string type

                                                                  

td> description
data type
digital Normal number converts a number to a string "number", such as a number 1 to a string "1"
nan to String "nan"
Boolean true convert string "true"
flase to String "false"
null to string "null"
undefined to string "undefined"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.