Write maintainable code
1, the minimum global variable can be used directly in JS without declaring the variable, so be careful not to use it without declaring it. (a global variable created unintentionally) such as a VAR declaration using a task chain. var a=b=12; the correct notation is var a,b;a=b=12; Technically, an implicit global variable is not a real global variable. Variables declared with Var can be deleted with the delete operator, but implicit global variables are not allowed, only one property of the global object. Properties can be deleted, variables are not available.
for---in traversal on non-array objects, also called enumerations. Although arrays are also objects in JavaScript, it is not recommended to use for--in--to iterate through arrays. There is an important way hasownproperty () can filter out attributes or methods inherited from the prototype chain. Avoid using eval () in JS, SetTimeout (); SetintervaL (); Function ();
//Reverse Example
setTimeout ("MyFunc ()", +);
setTimeout ("MyFunc (1, 2, 3)", +);
//Better
SetTimeout (MyFunc, +);
setTimeout (function () {
MyFunc (1, 2, 3);
}, +);
JS in the common self-executing function of the notation, 1. (function () {}) (); 2. (function () {} ()); 3,!function () {} (); 4,void function () {} ();
Return has an implicit semicolon, so when you write, if you return an object, the return is a line of curly braces.
The implementation of the inheritance between JS objects: Var a={say:function () {}};var b={__proto__: A};b inherits the methods and properties of a, and also has the Say method;
Before executing a piece of code, the browser will do some preparatory work. For example, the declaration of a variable, the assignment of this, is treated like a variable declaration for a function expression, and the function declaration is assigned directly to the function name. These three kinds of data preparation are referred to as the "execution context" or "execution context".
There are three types of code in ECMAScript, Function,eval,global
In-depth understanding of javascript--notes