Js organization memo (00)-Basics

Source: Internet
Author: User

1. Character Set

Unicode characters. Each character in Javascript (Js) programs is expressed in two bytes. A 16-bit Unicode code can represent every written language commonly used on the earth.

2. Data Type

Number)

All numbers are represented in floating point format, in a 64-bit floating point format defined in the IEEE 754 standard. Note that some integer operations (such as bit operations) are performed on 32-bit integers.

Some special numerical constants:

NaN (Number. NaN), special non-numeric value;

Infinity (Number. POSITIVE_INFINITY), positive Infinity;

-Infinity (Number. NEGATIVE_INFINITY), negative Infinity;

Number. MAX_VALUE, the maximum Number that can be expressed;

Number. MIN_VALUE, the smallest Number that can be expressed (closest to zero ).

-- Function isFinite (n) checks whether a number is NaN, positive infinity, or negative infinity.

String)

A single character is not of the char type. A string of 1 must be used.

Boolean)

Sometimes we can regard two possible boolean values as on (true) and off (false), or yes and no

Function)

Is an object with executable code"

Object)

Indicates "unordered set of named Data"

These named data are usually referenced (sometimes referred to as a domain) as the property of an object. The property can be any type of data (array, function, object ...).

In addition, there are some special objects, such as the Date class, RegExp class, and Error class.

Array)

Indicates an ordered set of numbered data"

Arrays can store any Js data type, including references to other arrays, objects, and functions.

Js does not support multi-dimensional arrays, but its array elements can also be arrays.

Js is a non-type language, so array elements do not have to have the same type.

Null and undefined)

Null indicates "no value", which is often regarded as a special value of the object type, that is, "No object ".

-- Boolean environment: false; Numeric environment: 0; string environment: "null"

Undefined returns this value when using an undeclared variable, a declared but unassigned variable, or an object attribute that does not exist.

-- Boolean environment: false; Numeric environment: NaN; string environment: "undefined"

Note:

(1) The operator "=" treats the two as equal

(2) The operator "=" or typeof () can distinguish the two.

 

Conversions between types-For details, refer to the authoritative guide P47

Number --> string: N. toFixed (n), N. toExponential (n), N. toPrecision (n)

String --> Number: parseInt/parseFloat (s, {p })

Boolean --> others: Numeric value, true-> 1, false-> 0; string, true-> "true", false-> "false"

Others --> Boolean: value, 0/NaN-> false, others-> true; string, empty string-> false, others-> true; others, null/undefined-> false, any non-empty object/array/function-> true

 

3. Packaging objects of Basic Data Types

Let's first look at two common string operations.

Var s = "Hello Word ";

Var last_word = s. substring (s. lastIndexOf ("") + 1, s. length );

Is s an object? Isn't the string of the basic type? From typeof (s), we can see that s is a string type. So why can string operations use Object Notation?

-- In fact, all three basic types have corresponding object classes, namely, Number, String, and Boolean classes. These classes are wrapper of the basic type ), it not only has the same value as the basic type, but also defines the attributes and methods used to calculate data.

Note: When a String is used in the object environment, the created String object instantly exists, so that we can access the attributes or methods. Once it is used up, it will no longer exist, the system will discard it.

The previous two lines of code are used as an example to test:

<Script type = "text/javascript"> var s = "Hello Word"; document. write (typeof (s); var last_word = s. substring (s. lastIndexOf ("") + 1, s. length); document. write ("<br/>" + typeof (s); </script> what is output on the page? The answer is --

String

String (it means that s only creates a String object instantly when using the properties or methods of its encapsulated object. If it is used up, it will be discarded, and s itself will not change)

However, to explicitly use a String object, you must create a non-transient object, such as S = new String ("Hello Word ");

Similarly, when we use a String object where the original String value is needed, Js will automatically convert the String object to a String.

For example, msg = S + "! ";

Here, the content about String values and String objects is also applicable to numbers, Boolean values, Number, and Boolean objects.

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.