JavaScript Data types

Source: Internet
Author: User

Undefined (undefined type).

Null (NULL type).

Number (data type).

String (String type).

Boolean (Boolean type).

1.undefined type

As shown in the previous example, the undefined type has only one value, which is undefined. When a declared variable is not initialized, the default value of the variable is undefined. For example:

var width;

This line of code declares the variable width, and the variable has no initialization value and is given a value of undefined.

2.null type

The type of only one value is null, which is a placeholder for "nothing" and can be used to detect whether a variable is assigned a value. The value undefined is actually a value of NULL derivation, so JavaScript

Define them as equal.

alert (null==undefined);//return value is True

Although the two values are equal, but their meanings are different, undefined means that the variable is declared but not assigned a value, and NULL indicates that the variable is given a null value.

3.number type

The most special type defined in JavaScript is the number type, which can represent both 32-bit integers and 64-bit floating-point numbers, and the following code declares variables that hold integer and floating-point values.

var inum=23;

var iNum = 23.0;

Integers can also be represented as octal or hexadecimal, octal first digits must be 0, followed by any octal digits (0~7), hexadecimal first digit must be 0, followed by any hexadecimal digits and letters (0~9 and A~F).

var iNum = 070;//equals decimal 65

var iNum = 0x1f;//0x1f equals decimal 31

For very large or very small numbers, you can use the scientific notation table floating-point numbers, which are also number types. Another special value, Nan (not a number), represents a non-count, which is the type of #.

typeof (NaN);//return value number

4.String type

(1) String definition

In JavaScript, a string is a set of text enclosed in quotation marks (single or double quotes).

var String1 = "This is a string";//defines a string string1

Unlike Java, JavaScript does not differentiate between "character" or "string", so the following statement defines a string as well.

var Onechar = "a";//defines a string with only one character "a"

(2) Properties and methods of characters

A string in the Javascripu language is also an object that is dependent on the Sreing object in Java. It also has a length property, which represents the string lengths (including spaces, etc.), calling the syntax format of length.

Grammar:

var str = "This is JavaScript";

var strlength = str.length;

The length of the last str string returned by Strlength is 18.

5.boolean Boolean type

The Boolean type is one of the most commonly used types in JavaScript, and it has only two values: True and False.

typeof (Variable or assigned value)

Undefined: If the variable is of type undefined, the undefined type result is returned.

If it is: Number Type or String, Boolean also returns the original type.

Object: If the variable is a null type, or if the variable is a reference type, such as an object, function, array, returns the result of type object.

JavaScript Data types

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.