Early examples of variables and function declarations in JavaScript

Source: Internet
Author: User

As shown in title, see the following example
(You can use the Chrome browser and then f12/or right-click to review the elements.) Bring up the developer tool and enter the console console input.
(Tip: Shift+enter can break code in the middle of the console input)

var name = "Xiaoming"; (function () {   var name = name | | "Xiao Zhang";  Console.info (name);}) ();//Xiao Zhang (function () {  name = name | | "Xiao Zhang";  Console.info (name);}) (); Xiaoming (function () {  var name2= name;  var name = name | | "Xiao Zhang";  Console.info (name, name2);}) (); Xiao Zhang undefined

The execution is as follows:



The explanations are as follows:
In JavaScript,
function xxx () {  //A heap of code  ... // ...  var name2 = name;  var name = name | | "Xiao Zhang";  A bunch of code}

Execution will become this equivalent form:
function xxx () {  var name2 = undefined;  var name = undefined;  Other Var will also be advanced to the beginning  //heap of code  ... // ...  name2 = name;  Name = Name | | "Xiao Zhang";  A bunch of code}

You can also refer to the Bootstrap Chinese web tutorial advanced in JavaScript for variable and function declarations (hoist)

Date: 2014-11-07

Author: anchor (HTTP://BLOG.CSDN.NET/RENFUFEI)


Early examples of variables and function declarations in JavaScript

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.