JavaScript Advanced Program Design reading notes (ii) Introduction of JavaScript

Source: Internet
Author: User

Chapter III: Basic Concepts

There are 5 simple data types (also known as basic data types) in ECMAScript:Undefined\null\boolean\number\string, There is also a complex data type --object,object essentially consists 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 declare a variable using var but do 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 , which is null. represents an empty object pointer.

var car = null;

Alert(typeof car); "Object"

if (car! = null) {

to perform an action on a car Object

}

undefined the value is derived from a null value.

a      lert (null = = undefined); True

As long as the variable that is intended to hold the object does not actually hold the object, you should explicitly keep the object in a 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 Span style= "COLOR: #000000". Positive_infinity - in finity number ) .

NaN( No t a number)

1. any operation involving Nande will return NaN.

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 call the object's valueOf () method First, if it cannot be converted to a number, and then call the toString () method based on the return value .

Numeric conversions:

A function that converts a non-numeric value to a number:

1. number () for any data type, not parsing 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 () for string types (ignoring 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: you can use double quotation marks or single quotation marks.

  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 () can pass in the cardinality parameter, representing the output's binary representation, 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. See example · •

However, the use of the WITH statement in large numbers can cause performance degradation and also make debugging code difficult, so it is not recommended to use the WITH statement when developing large applications .

s Witch statement:

The switch statement uses the congruent operator when comparing values, so no type conversions occur (for example, the string "Ten" is not equal to the number ) .

The return value of the function:

In addition to the return statement, there is no declaration that the function returns a value. In addition, The return statement can be returned without any return value, at which point the function returns undefined after it has stopped executing .

Ecmas function parameters of Cript: Key

Named parameters are provided for convenience only, but are not required. The parser does not validate named parameters.

the arguments in the ECMAScript are internally represented by an array, and can be arguments object to access the parameter array, which accesses each parameter.

modifying The value in the arguments object automatically reflects the corresponding named parameter, but modifying the named parameter does not change The value of the arguments. No pass-worthy named parameters are automatically assigned the undefined value.

all parameters in the ECMAScript are passed as values, and arguments cannot be passed by reference.

the ECMAScript function cannot be overloaded and can be overridden.

JavaScript Advanced Program Design reading notes (ii) Introduction of JavaScript

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.