4 kinds of pre-interpretation without moral integrity in JS
- 1. if语句即使条件不成立,条件里的表达式也会进行预解释.- 2. 匿名函数的预解释: 只对等号左边与解释- 3. 自执行函数的预解释: 不进行预就解释, 执行的时候,定义+执行- 4. return下面的语句也会进行预解释,但是return后面的语句不进行预解释
<script> var p1 = {name: "Maotai"}; Console.log (age); 1. Even if the condition is not established, the expression in the condition will be pre-explained. if (' Age ' in p1) {//is an attribute of the object var age = 22; Console.log ("name in P1")} console.log ("--------------------------------"); 2. Pre-interpretation of anonymous functions: only to the left of the equals sign with the explanation FN (); function fn () {Console.log ("FN is running!"); } fn (); Console.log ("--------------------------------"); The right side of the equals sign is not pre-interpreted. FN2 (); Error var fn2 = function () {var favor = "Orange"; Console.log ("Fn2 is running!") }; FN2 (); 3. Pre-interpretation of self-executing functions: Do not pre-interpret, execute, define + Execute ~function (num) {console.log ("I am zi Zhi xing fun" + num); } (100); 4, return the following statement will also be pre-explained, but return after the statement is not pre-interpretation console.log ("--------------------------------"); function Fn3 () {console.log (num3); return function () {}; This function does not perform with the explanation of var num3 = 330; This will be pre-explained} fn3 (); </script>
[4 Non-moral integrity pre-interpretations in Js]js