I have been exposed to the JavaScript language for a long time, but I have never systematically understood such a language. I have just graduated and have no intention of working for some reason to systematically understand this language, and I also want to develop the habit of writing blogs through this language, because I think this is a sacred and glorious thing for programmers.
1.1 Background
I believe that what many beginners forget or confuse is the official name of JavaScript: ECMAScript. On June 17, 2015, ECMAScript 6 was released, namely ECMAScript 2015.
1.2 Syntax
General syntax omission
Highlights:
1. Original value and object: Original value includes boolean values, numbers, strings, null, and undefined. The other values are objects. The main difference between the two is how they are compared: each object has a unique identifier and is only equal to itself.
var obj1={};var obj2={};alert(obj1 ===obj2);//falsealert(obj1===obj1);//truevar prim1=123;var prim2=123;alert(prim1===prim2);//true2. Use typeof and instanceof to classify values.
typeof
| Operands | result |
| undefined | 'undefined' |
| null | object |
| Boolean value | boolean |
| number | number |
| String | string |
| function | function |
| All other regular values | object |
| Values created by the engine | The JS engine can be allowed to create some values, and the result of typeof can return any string |
3. Boolean value:
False value: undefined,null,false,-0,NaN,''
Binary logic operator: The binary logic operator in JavaScript is short-circuited. If the first operation is sufficient to determine the result, the second operation will not be evaluated. &&): If the first operation is a false value, return it. or (||): If the first operation is the true value, return it.
4.IIFE:
Introduce new scopes. Function: Remove unintentional sharing caused by closures (functions and variables in the surrounding scopes to which it is connected).
example:
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 return value of this line marked (1) is always the current value of i, not the value at the time the function was created. After the loop ends, the value of i is 5, so all functions in the array return this value. If you want the function tagged (1) 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 all part of the knowledge that has not been paid attention to or learned before during the collation process. It is written here as a supplement to the knowledge points.
The above basic JavaScript key points (must read) are all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.