Home > Web Front-end > JS Tutorial > A brief explanation of JavaScript types_Basic knowledge

A brief explanation of JavaScript types_Basic knowledge

WBOY
Release: 2016-05-16 18:20:12
Original
867 people have browsed it

Primitive types are stored directly on the stack, and reference types are stored on the heap.

Primitive types are divided into the following 5 types: Undefined, Null, Boolean, Number, String

Undefined type:

Undefined type has only one value : undefined. When a variable is declared uninitialized, its default value is: undefined.

When a function has no clear return value, it also returns a value: undefined

Null type:

Null type has only one value: null. Value undefined It is actually derived from the value null, so ECMAScript defines the two as equal:

alert(null==undefined);//outputs: "true"

null and undefined values Equality means different meanings: undefined is the value assigned when the variable is declared but not initialized; null represents an object that does not exist. If the function returns an object, then when the object is not found, null is returned.

Boolean type:

Boolean type has 2 values: true and false

Number type:

The Number type can represent 32-bit integers or 64-bit floating point numbers.

The default integer is decimal, which can also be expressed in octal (the first digit is 0, such as 070, corresponding to decimal 56), or hexadecimal (the first 2 digits are 0x, such as 0xAB, corresponding Decimal 171).

No matter what base the number is represented in, the result of the operation is the decimal result.

To define a floating point number, there must be a decimal point and 1 decimal place after the decimal point, such as var f=2.0. Floating point numbers are stored as strings.

String type:

Strings are declared with double quotes (") or single quotes (').

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template