"Precompilation phase" and "execution phase" during JavaScript run

Source: Internet
Author: User

JavaScript is a weak type of language relative to other languages, and in other Java languages, the execution of a program requires a compile stage

There is a similar "precompilation phase" in JavaScript (JavaScript precompilation is scoped to a block of code, i.e., each code block encountered is precompiled > <script></script> execution ),

First, in the popular science of JavaScript in two ways of declaring, Var and function, the former declares a variable, the latter is a method of declaring

In precompilation, JavaScript makes two kinds of processing schemes for both declarations.

<script> var a = "1";  Declare variable a   function  B () {//Declaration method B      alert ();  }  varfunction() {    //Declare variable C alert (); }</script>

In the above code block, a, c is the variable assignment, B is the function declaration, when the above code is executed,

The first step is to go to the pre-compilation stage

Assigning A to a variable, C creates a memory space in memory and points to the variable name, and assigns a value of undefined

For function declarations, memory space is also created, but assigned objects assign values to function names

precompilation phase: (PS: Variables are declared and functions are declaredin the precompilation phase, regardless of the order in which the variables are declared and declared in the code)

<script> var a = undefined;      var c = undefined;
    
var B = function() {alert (); }
</script>

Implementation phase:

<script>= "1"function() {alert (); }</script>

Overall implementation steps:

<script> var a = undefined;         var c = undefined;     varfunction= "1"function() {alert (); }</script>

Topic:

<script> var a = "1";       function  B () {alert (a);     var a = "2"; } b (); </script>

PS: Variables and function declarations relative to the window environment, each scoped to the variables and functions under it

<script>      Functionhello () {        alert ("Hello");       }        Hello ();    </script>   <script>   Functionhello () {          alert ("Hello World");     }       Hello ();   </script>
<script>   
function Hello () {        alert ("Hello");       }        
function Hello () {          alert ("Hello World");     }       Hello ();  </script>

Blog: http://www.cnblogs.com/alex-web/

Note: The yy of the Little crazy paper

"Precompilation phase" and "execution phase" during JavaScript run

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.