JS Learning Notes

Source: Internet
Author: User


Javacript notes
According to EC5.0
A total of six data types:
Number,string,bool
Undefine,null
Object (Generalized)--->object (narrowly), array,function

The first five kinds are called primitive type, and the last one is complex object
Three ways to determine the type of object:
Typeof,instanceof,object.prototype.tostring

typeof the first three types are basic types
typeof undefined is undefined
typeof null is an object//for historical reasons, in order to be compatible with the previous code, it does not mean that NULL is a
typeof [] is an object

The difference between null and undifined:
NULL indicates null value
Undefined indicates no value exists

In fact, all data can be thought of as generalized objects, or called by object mode.
var s = new String ("123");//s is an object
These six values are false:undefined,null,0, "", False,nan

Automatic semicolon addition: JavaScript engine

Error type:
The most common type of error Eooro
Six Types of errors
Systaxerror
Reference Error
Rangeerror
TypeError
Urierror
Evalerror no longer appears in//EC5

Function:
Three ways to declare functions
1. Function command
function print (s) {
Console.log (s);
}
2. function expression Assignment variable
var print=function (s) {
Console.log (s);
}
Function name should not be added, if added, only valid inside the function
3, function constructor//Few people use
var print=new Function ("s", "Console.log (s)"); The last argument is the function body, and the previous parameter, if present, is the function's argument
var print=function ("s", "Console.log (s)");

As a first-class citizen: functions can be used as other data types, such as the ability to assign function names to variables and objects, or to other functions as arguments, or as a result of a function. As a result, the function gets promoted as a variable declaration.
Declaring a function using an assignment variable causes it to be declared first and then assigned. In other words, the variable is promoted, but not yet assigned a value. As a result, the JS engine always determines the definition of an assignment statement when the same function is declared in the same way that it uses function commands and variable assignments.
var f = function () {
Console.log (' 1 ');
}

function f () {
Console.log (' 2 ');
}

F ()//1

According to the ECMA specification, functions cannot be declared in non-functions, but actual fools, many browsers can run. However, because of the variable promotion, this intent uses the conditional statement to determine whether the declaration is actually not effective. Therefore, to achieve the effect of a conditional statement, you can use only function expressions

Properties of the function:
Name: Names of functions
The number of arguments for the length function

Scope:
The block block itself does not form a scope, so {} is only used for syntax structures such as for,if,while,function
Therefore, scopes are divided into two types: global scope and function scope.

Variables within a function scope override global variables
Variable promotion is also present in variables within the scope of the function
The parameters of the function can be omitted, if omitted, the value is undefined

About the value and address of the pass:
In C #, if the passed parameter is a primitive type (int,float, etc.) or struct (struct), it is a call to value.
If the passed argument is a class, then it is a reference call. (However, when the function internally changes the object as a whole, the value is still passed)
If there is a ref or out keyword before the passed argument, it is a reference call.
In JS, the first two are also established. Of course, the object here is generalized, which includes objects, functions, and arrays.

Arguments[] object contains all parameters when the function is run
But arguments, though very much like an array, is not an array, but an object--! So arrays of methods such as slice and foreach
Slice (i,j) method, if the array is used, then from the I position, cut to the J position, return the new sub-array, the original array is unchanged.
If string is used, a new substring is returned, and the original string is unchanged.

JS Learning Notes

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.