1. In the Try-catch statement, the finally clause is optional, and when the finally clause is included, the return statement in either the try or catch statement is ignored. So, when we use the finally clause, we need to be clear about how we want the code to execute.
function fn () { try { a++ ; } Catch (Error) { Console.log ("in Catch"); return ; } finally { Console.log ("in finally");} } fn (); // In catch in finally
2. Void in Jvascript is an operator that specifies to evaluate an expression and return undefined. For example, the underscore uses void 0 instead of undefined.
3, undefined is not a reserved word (reserved word), it is only a property of the global object, in the low version of IE can be rewritten. So the direct use of undefined may not be reliable. So how do you ensure that the value of undefined is guaranteed to be taken? The following two scenarios can be used:
jquery version:
(function(window, undefined) { //...}) (window);
The advantages of this writing:
- Both window and undefined are designed to reduce the scope scope of variable lookups. When the window is passed to the inside of the closure, it can be used as a local variable when using it inside the closure, which is obviously faster than the original search under Window scope. (The original window is at the top of the scope chain, and the lookup speed is slow)
- In jquery compressed version jquery.min.js, you can replace the local variable window with a single letter, reducing the file size and increasing the load speed.
- Pass undefined as a parameter to the closure, because the value is not passed to it, and its value is undefined. So you can get the exact undefined.
Version underscore:
function (obj) { returnvoid 0;}
4.
JavaScript error-prone knowledge