JavaScript Advanced Programming Reading notes (two) JavaScript basic concepts

Source: Internet
Author: User

Chapter III: Basic Concepts

ECMAScript There are 5 simple data types (also called basic data types):Undefined\null\boolean\number\string, Another complex data type , --object,object , is essentially composed of a set of unordered name-value pairs.

typeof is an operator and not a function .

Undefined Type: This type has only one value , which is Undefined. when you use var to declare a variable but not initialize it. The value of this variable is undefined.

var message;

var message2 = undefined;

alert (message); "Undefined"

Alert (message = = undefined); True

Alert (typeof message); "Undefined"

Alert (message = = undefined); True

alert (age); Error generated

Alert (typeof age); "Undefined"

null type: This type has only one value , or null. represents an empty object pointer.

var car = null;

Alert(typeof car); "Object"

if (car! = null) {

to run an action on a car Object

}

undefined the value is derived from a null value.

a      lert (null = = undefined); True

Simply to save the object's variables without actually saving the object, you should clearly let the object save the null value.

Num ber type:

The first digit of octal is 0, the top two hexadecimal digits are 0x .

Scientific Counting method: e

ecmascript The smallest and largest values that can be represented are: number number . Max_value, out of range. will be in finity number - in finity number ) .

NaN( No t a number)

1. the Nande operation will return NaN Regardless of what is involved.

2. NaN is not equal to any value, including NaN itself .

alert( NaN = = Nan ); false

IsNaN () attempts to convert the value to a numeric value after it has been accepted.

a Lert (IsNaN (NaN))              ; True

a Lert (IsNaN (Ten))              ; False

a Lert (IsNaN ("ten"))              ; False

a Lert (IsNaN ("Blue"))              ; True

a Lert (IsNaN (True))              ; False ( can be converted to 1)

IsNaN also applies to objects, which first call the object's valueOf () method, assuming it cannot be converted to a numeric value. the toString () method is then called based on the return value .

Numeric conversions:

A function that converts a non-numeric value into a numeric value:

1. number () for no data type, no parsing of octal

var str;

var str2 = null;

var str3 = "Hello World";

Number (str); NaN

Number (STR2); 0

Number (STR3); NaN

Number (""); 0

Number ("000011"); 11

Number (true); 1

Number ("0xA"); 10

The unary plus operator operates in the same way as number () .

2. parseint () is used for string types (ignoring the preceding spaces) to parse octal

parseint ("1234blue"); 1234

parseint (""); // NaN

parseint ("0xa"); // ten

parseint (22.5); //

parseint ("8"); // (Specify cardinality.) i.e. 8 binary )

parseint ("Ten", 2); // 2

3. parsefloat () is used for string types (ignoring the preceding spaces), parsing only the ten -Binary

Parse                Float ("1234blue"); 1234

Parsefloat ("0xA"); 0

Parse                 Float ("22.34.5"); 22.34

Parsefloat ("0908.5"); 908.5

Parse                Float ("3.125e7"); 31250000

String type: able to use double-cited. can also be represented by a single citation.

  except null undefined Value does not have to string () null undefined can call string (), returns the corresponding string. That is null value back "undefined"

ToString () is able to pass in the cardinality parameter, which represents the binary representation of the output. such as:

var num = ten;

Number.tostring (2); "1010"

to convert a value to a string, you can use the plus operator to match it to an empty string ( "" ) to add together.

With statement:

The function of the WITH statement is to set the scope of the code to a specific object. The goal is to simplify the work of writing the same object multiple times. Examples See · •

However, a large number of using with statements can cause performance degradation and, at the same time, cause debugging code to be difficult. It is therefore not recommended to use the WITH statement when developing large applications .

s Witch statement:

The switch statement uses the congruent operator when comparing values. Therefore, type conversions do not occur (for example,. The string "Ten" is not equal to the value of ten).

The return value of the function:

In addition to the return statement. No matter what the declaration indicates, the function returns a value.

Other than that. return The statement can also be returned without any return value, at which point the function will return after it has stopped running. undefined .

Ecmas function parameters of Cript: Key

The named parameters are only convenient, but not necessary. The parser does not validate the named parameters.

the parameters in the ECMAScript are represented internally by an array. The ability to access This array of parameters through the arguments object, so that each participant can be interviewed.

Changes to the values in the arguments object are self-reflective to the corresponding named parameters. However, changing the name of the reference does not change the arguments corresponding value.

The undefined value is assigned to itself without the passing of a worthy named reference .

all the parameters in the ECMAScript are passed as values, and it is not possible to pass the parameters by reference.

the ECMAScript function cannot be overloaded and you can overwrite it.

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

JavaScript Advanced Programming Reading notes (two) JavaScript basic concepts

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.