JavaScript data types

Source: Internet
Author: User

Data type

First, the underlying type value includes: Undefined, null, Boolean, string, number

The underlying types occupy large and small spaces in memory, and their values are stored in the stack space , which we access by value .

Undefined: Declares a variable that has no definition (only one value).

<script>

var TTT;

Alert (TTT)

</script>

Null:null indicates that the object is ready to be saved, and the value of the object is not actually saved.

var car = null;

Alert (typeof (CAR))

Boolean: Boolean value has two values, one is true, and one is false.

String: Used to represent a sequence of characters consisting of 0 or more characters, that is, a string. Strings can be represented by double quotation marks and single quotation marks.

Number: Used to represent integers and floating-point values, as well as a special value, Nan.

Broaden a little knowledge of the difference between null and undefined:

Different types, uninitialized defined values are detected with typeof ' undefined ', and null values are detected with TypeOf ' object '

Second, reference types include: objects, arrays, functions, etc.

Objects (object type): var obj = {name: "Mulan", Age:20,sex: "Female"}

Alert ("The name is" +obj.name+ "age is" + ... )

For values of reference types, you must allocate space for this value in heap memory . Because the size of the reference type value is not fixed (the object has many properties and methods, and you can add properties and methods dynamically), you cannot save them in the stack memory. However, the memory address size is fixed, so the memory address can be stored in the stack memory .

In short: The stack memory holds the base data type value, and the heap memory holds the reference type value. The address of a reference type value in memory is stored in the stack, which is what we often call an object reference (pointer).

See:

Iii. type Conversion

1. Number ()

Example: var num1 = "11";

var num1 = number (NUM1);

var num2 = 12;

var num3 = num1+num2;

alert (num3);//23

2. parseint () function

Converts a string to a numeric value of an integer type

Features: Directly check if the value pattern is met, he ignores the space in front of the string until the first non-whitespace character is found.

If the first character is not a numeric character or a minus sign, parseint () returns Nan.

In other words, converting an empty string with parseint () returns Nan

3, parsefloat ()

Converts a string to a numeric value of a floating-point number type

4. ToString ()

Values of all types except undefined and null have his ToString () method, which functions as a string representation of the returned object

5, String ()

NULL returns null undefined return undefined

6. Boolean ()

Convert any type of value to a Boolean value

The following values are converted to False:false, "", 0, NaN, null, undefined

Any remaining value will be converted to true

JavaScript data types

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.