JavaScript runtime environment and scope chain

Source: Internet
Author: User

operating Environment : the environment in which JavaScript code snippets are executed (can be understood as scopes in C/s + +)"Personal understanding"

Variable Object : The first is an object that holds all the variables and functions of the current execution environment (JavaScript functions can be nested, C + + is not as if (the new version seems to be possible))

Correspondence Relationship : Each execution environment has an associated variable object

scope chain : chain, linked list.

Function: Ensures an orderly access to all variables and functions that the execution environment has access to (what ghost, the language of the test?) )

Current variable object → variable object containing environment → variable object containing environment ... → Global execution object's variable object

Note: There is no concept of block-level scope in JavaScript

if (true) {    var color = ' red ';} Console.log (color);

is correct in JavaScript and is incorrect in C + +

The following code is problematic

function Outfun () {    var color1 = ' yellow ';     function Innerfun ()  {        var color2 = ' green ';    }    Console.log (COLOR2); // not correct }

Why is it wrong? JS is not a block-level scope, yes there is no block-level scope. But there is an execution environment (scope)

The execution environment of the COLOR2 here is valid in Innerfun (the scope of C + + is understood)

JavaScript runtime environment and scope chain

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.