The language has been in contact with JavaScript for a long time, but it has never been systematically understood. Take advantage of the current graduate and some reason not to work the situation of the system to understand the language, but also want to use such language to develop the habit of blogging, because I think it is a very sacred and glorious thing for programmers.
1.1 Background
It is believed that many beginners have forgotten or confused the official name of JavaScript: ECMAScript. June 17, 2015, ECMAScript 6 issued an official version, that is, ECMAScript 2015.
1.2 Grammar
General syntax ellipsis
Emphasis is placed on:
1. Original values and objects: The original values include Boolean values, numbers, strings, null, and undefined. The other values are objects. The main difference between the two is the way they compare: Each object has a unique identity and is equal to itself.
var obj1={};
var obj2={};
Alert (obj1 = = obj2);
False
alert (OBJ1===OBJ1);
True
var prim1=123;
var prim2=123;
alert (PRIM1===PRIM2);
True
2. Use typeof and instanceof to classify values.
typeof
Number of operands |
Results |
Undefined |
' Undefined ' |
Null |
Object |
Boolean value |
Boolean |
Digital |
Number |
String |
String |
Function |
function |
All other general values |
Object |
Value created by the engine |
The JS engine can be allowed to create some values, and typeof results can return any string |
|
|
3. Boolean value:
False value: Undefined,null,false,-0,nan, "
Binary logical operators: The two-yuan logical operator in JavaScript is shorted. If the first shipment is sufficient to determine the result, then the second operation will not be evaluated. With (&&): If the first shipment count is a false value, return it. or (| | ): If the first count is the truth, return it.
4.IIFE:
Introduce a new scope. Effect: eliminates unintended sharing of closures (functions and variables in the surrounding scopes to which they are connected).
Cases:
var result=[];
for (Var i=0;i<5;i++)
{
Result.push (function () {return i;}); /(1)
}
Console.log (Result[1] ());//5 (not 1)
Console.log (Result[3] ());//5 (not 3)
The line that is marked (1) returns the current value of I, not the value of the function when it was created. After the loop ends, the value of I is 5, so all the functions in the array return this value. If you want to mark (1) This line of functions to get a snapshot of the current I value, you can use Iife.
for (Var i=0;i<5;i++)
{
(function () {
var i2=i;
Result.push (function () {return i2});
} ()
) ;
}
This is in the process of sorting out the previous or not aware of some of the knowledge, write here to do the supplement of knowledge points.
Above this JavaScript basic focus (must see) is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.