JS Learning Essays

Source: Internet
Author: User

First, the data type

1. Basic type:

Number can use the isNaN function to detect if a parameter is "not a value",

When you need to display special characters in a string code, use a backslash (\) to escape,

Boolean any non-empty string can be converted to true, any non-0 numeric value (including infinity) can be translated to True,

Null, undefined is null==undefined in JavaScript, but null===undefined is false,undefined can be considered an unexpected system error, and NULL is a "null" in the program's expectation, If you want to assign a value to a variable or property, it's best to choose NULL

2. Object type: Objects (Array, Function, Date ...) )

An object can be considered an unordered collection of attributes, each of which is a name/value pair;

Two ways of creating objects: (1), Var obj=new object ();

Obj.name= ' xiaoming ';

obj.age=20;

(2), Var obj={

Name= ' Xiaoming ',

Age=20

}

Note: You must enclose the attribute name with spaces, special characters, or reserved words, such as: Var obj={

' Name ' = ' xiaoming ',

' Class Name ': ' Classthree '

}

The property value is accessed in two ways: (1), object. Property name, such as document.write (obj.name); use more of the dot operator in actual development

(2), Object [' attribute name '], such as document.write (obj[' name ');

Delete attributes: Delete object. property name, such as delete obj.name; object can be used in development. The hasOwnProperty ("property name") function determines whether the property is contained in the object and returns False if it contains true.

Note: Setting the property to null or undefined only removes the association of attributes and values and does not actually delete the attribute, so the property is still present in the object.

Second, array

Two ways to use: 1, using the array constructor, such as: Var arr=new array (); arr[0]=1;arr[1]=2;arr[2]=3; or var arr=new array (three-way);

2, the use of literal notation, such as: Var arr=[1,2,3];

Third, function

The function can be passed as a value: for example, Function FuncName (somefunc,someparam) {

Return SomeFunc (Someparam);

}

function sum (num) {

return num+3;

}

var result=funcname (sum,5);

Function call Pattern: 1, method invocation mode, such as Var myobj={

Param1:1,
Param2:2,
Sum:function () {

Return this.result=this.param1+this.param2;//this refers to the current object

}

};

Myobj.sum ();//Output 3

2, function call mode, such as Var add=function (A, b) {or function add (a, b) {

return a+b; return a+b;

}; }

Add (2,3);//Output 5

3, constructor call pattern, such as Var add=function () {///differs from the way the literal object property calls the function, here this.name is ";" And it's not ","

This.name= ";

This.sum=function (A, b) {

return a+b;

}

}

var obj=new add ();

obj.sum;//Output 3

JS Learning Essays

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.