Javascript development technology-Chapter 1 js Data Types

Source: Internet
Author: User

3.1 Basic Data Types
1. string type (string): it consists of unicode characters, numbers, and punctuation marks. In javascript, there is no char character type. A string must be used even if it only represents one character.
2. number: the integer and floating point types are not differentiated.
3. boolean)
3.2 Composite data types
1. array: array element: the data in the array is called an array element.
Array Subscript: numbers starting from 0
Read: arr [0];
Value assignment: arr [1] = 120;
2. Object:
Object Name. attribute name
Object Name. Method Name ()
3.3 Other data types
Function:
1. Functions in javascript are a data type, so they can be stored in variables, arrays, or objects.
2 null: In javascript, null is an independent data type, which indicates no value.
3. undefined indicates undefined. In four cases, undefined is returned.
A. defines a variable but has not been assigned a value.
B. An undefined variable is used.
C. defines an object attribute that does not exist.
D. referenced an array element that does not exist.
3.4 Data Type Conversion
Principle: Convert the data type to the data type required in the current environment.
Implicit conversion rules for javascript Data Types
1. implicit conversion of data types:
Original data type Number of votes Data Type Description
String Non-Null String Digit acquisition

If the character in a string is a number, it is converted to a string number, for example, "123" is converted to a number of 123,

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

Boolean True
NULL characters Number Type 0
Boolean Flase
String "true" Number Type Nan
Boolean True
Field string "flase" Number Type Nan
Boolean True
Number Type Common number String Converts a number to a string "number"
Boolean Convert the number 0 to false, and convert other numbers to true.
Nan String type Convert to string "Nan"
Boolean Convert to false
Boolean True String type Convert to string "true"
Number Type Convert to 1
False String type Convert to string "false"
Numerics Convert to 0
Null String type Convert to string "null"
Number Type Convert to 0
Boolean Convert to false
Undefined String type Convert to string "undefined"
Number Type Convert to Nan
Boolean Convert to false

2. implicit conversion of alternative data

3. Display and conversion of data types

1. Convert to numeric type

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

. ParseInt (value) converts a value to an integer.

. ParseFlaot (value) to floating point

Cannot be converted to numeric type. Nan is returned.

Conversion rules for converting other types to numeric types

Data Type Description
String Null String Use Number () to convert to 0, use parseInt () and parseFloat () to convert to Nan
String "ture" Convert to Nan
String "false Convert to Nan
Other strings

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

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

Boolean True Use Number () to convert to 0, use parseInt () and parseFloat () to convert to Nan
False Use Number () to convert to 0, use parseInt () and parseFloat () to convert to Nan
Null Use Number () to convert to 0, use parseInt () and parseFloat () to convert to Nan
Undefined Convert to Nan

2. Convert to boolean

Convert other data types to boolean

Data Type Yuming
String Null String Convert to false
String "true" Convert to true
String "flase" Convert to true
Other strings Convert to true
Number Type 0 Convert to false
Nan Convert to false
Other numbers Convert to true
Null Convert to false
Undefined Convert to false

3. Convert to string type

Convert other data types to string type

Data Type Description
Number Type Common number Converts a number to a string "Number", for example, a Number 1 to a string "1"
Nan Convert to string "Nan"
Boolean True Convert to string "true"
Flase Convert to string "false"
Null Convert to string "null"
Undefined Convert to "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.