Summary of JS section

Source: Internet
Author: User
Tags null null variable scope

One. Lexical structure

1. case-sensitive

2. Note//single line/* Multiline Comment *

3. Literal (direct Volume Literal)




' Hello '






    1. Identifier {variable} and reserved word
    2. Semicolons can be omitted but may cause problems, JS will automatically fill;

var y = x+f

(a+b). toString ()

Equivalent to

var y = x+f (a+b). toString ();

Two Type. Values and variables

1. The original type Number. string and Boolean null null undefined not defined

2. Object type

3. Class Array Function Date RegExp Error

Garbage collection is integrated in the 4.js parser

5. Arbitrary JS value Dou can be converted to a Boolean value






"" are converted to false

6. Packaging Objects

var s= "hello";//primitive type (no METHOD)

S Len = 4;//when A property or method of the original type is called (the original type has no properties and Methods)

Whenever a property or method that references a string is referenced, the new string (s) is called to wrap the original type into an object

As soon as the call to S.len is called the property and method of the string object, the newly created temporary object will be destroyed once the reference has ended

var n = s.len;//this is undefined

Alert (n);

A temporary object that is created when a property or method of a string Boolean number is Called. is the wrapper object display defines the wrapper object var s=new String ("hello")

var s= "hello": is different

7.== and = = =

= = For general comparison, = = = for strict comparison, = = In comparison can be converted data type, = = = Strict comparison, as long as the type does not match the return Flase.

8. Type Conversion

var n = 17;

Alert (n.tostring (2)); Binary 10001

Alert (n.tostring (8));//021

Alert (n.tostring (16));//0?21

Alert (n.tostring); Alert (n.tostring ());

9.toString () valueOf ()

var date = new Date (2011,1,3);

Date.valueof () returns the time represented by the number of milliseconds

10.JS is a dynamic type var n = 10; The type of the variable is determined during program run

11. Variable Scope

function scope and declaration in advance

Variable declarations defined within functions are automatically advanced to the top of the function

12. Scope Cope Chain

In a function body that does not contain functions, the scope chain has two objects, the first of which is the definition of a function. the object of the parameter and local variables, and the second is a global object. Within a nested function body, There are at least three objects on the scope chain. When a function is defined, it saves a scope chain call function, It creates a new object to store its local variables, and adds this object to the saved scope chain, while creating a new "chain" that represents the scope of the function Call. For nested functions each time an external function is called, the inner function is redefined again. The scope chain is different each time an external function is Called.

Delete in eval void

Chapter I. Objects

    1. Basic operation of object create set query Delete test enumerate
    2. The property properties of the object can be written to enumerate configurable (can be deleted)
    3. Object properties of the object

Prototype of the object prototype

The class of the object that identifies the string of the object type

Whether an extended tag for an object can add a new property

Three ways to create objects

    1. Object Direct Amount

var empty={};

var point = {x:0,y:0};

    1. New Create Object

var 0 = new Object{};//empty object Same as {}

var a = new array{};

    1. object.create{}

var O1 = object.create{(x:1,y:2)}; O1 inherited from Object prototype {x:1,y:2}

var O2 = Object.create{null};//o2 does not inherit any properties and methods

var O3 = Object.create (object.prototype);

Empty objects are the same as {}new object ()

7. operation of the property as an object of an associative array

object["property"] hash Map Dictionary associative array

8. Inheritance

JS inheritance can only get the value of the property from the parent class, and cannot modify the prototype chain

If the object book is null or undefined

Book.subtitle.length will make an Error.


var len = Book && book.subtitle && book.subtitle.length;

Delete Property

Delete Book.subtitle

Detection properties in Hasownpreperty () propertyisenumerable ()

var o = {x:1};

"x" in O

"toString" in O

hasownpreperty{}; determine whether the property is your Own. Inheritance property returns False

propertyIsEnumerable () is only a property of its own and can be enumerated

Get all Properties

Object.keys ()

Object.getownpropertynames ()

9. Property Getter and setter

var o = {



Set R (value) {value = this.r;},

Get R () {return this.x + this.y;}};

X data properties, R accessor properties

10. Attributes Ecmascript5 old IE does not support the following usage

attribute of the data attribute: value of the writable writable

Enumerable enumerable

Configurable configurable

Accessor attribute properties: Get set

Enumerable enumerable

Configurable configurable

Return {value:1,writable:true,emunerable:true,configurable:true}

Object.getownpropertydescriptor ({x:1},x)

Property returned undefined not found

Setting property properties Cannot modify inherited property attributes

Object.defineproperty ()

Set non-enumerable Properties

var o = {};

Object.defineproperty (o, "x", {






Set Read-only

Object.defineproperty (o, "x", {writable:false})

modifying multiple Property attributes

Object.defineproperties ()

Extended Object.prototype Book P137

11. Three properties of an object

Prototype Class extensible attribute

Querying the prototype of an object

Ecmascript5 in Object.getprototypeof (o1)

ECMASCRIPT3 in O1.constructor.prototype

Objects created by object direct amount or New object ()

A property that contains a constructor that is the constructor of the object ()

Constructor.prototype is the real prototype.

P.isprototypeof (O) detects if the object P is a prototype of O

Gets the type string of the object (o1). Slice (8,-1)

12. Scalability of objects

Whether the object can be newly added to the property

Object.preventextensions () Setting object is not extensible

Object.isextensible ()

Object.seal () In addition to setting the object to not be extensible, also set the property to not be configured

Object.freeze ()

In addition to setting the object to not be extensible, set the property to not configurable and set the property to Read-only

8th Chapter function

1. Function call, method call

function T () {}

T (); Function call this is the global object in strict mode is undefined

var o = {a:function () {}};

O.a () method Call this is the object that is currently being called

2. Constructor calls

var o = new Object (); var o= new Object;

o The This object is inside the prototype property that inherits from the constructor

var r = new O.M (), in which this is not O

The execution of the 3.p184 function is scoped to the scope chain, which is created when the function definition is in Effect.

The nested function f () is defined in the scope chain, where the variable scope is a local variable

Scope chain

Calling s () creates the execution environment (the calling Object) of the function s, places the object at the beginning of the list, and then links the calling object of the function T to the next, and finally the global Object. Then look for the variable from the beginning of the list name call SS () SS () ==> t () ==> window

Name= "lwy";

function T () {

var name= "tlwy";

function S () {

var name= "slwy";

Console.log (name);


function SS () {

Console.log (name);


S ();

SS ();


T ();

Each time a function is called, a new scope chain is Generated. Including the new internal variables

Summary of JS section

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: 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.