Chapter fourth variables, scopes and memory issues (II)

Source: Internet
Author: User

Alert (typeof a);//undefined    a = function () {        var a = ' 2 ';        return A;    };    Alert (typeof a);//function    alert (typeof A ());//number

  

2, instanceof

var obj = {Obj:1};    Alert (obj instanceof Object);//true

  

var num = 1;alert (num instanceof number);//false

The values of all reference types are instances of object, so the instanceof operation conforms to always return true when the reference type value and the object constructor are detected. Returns False if it is used to detect the base type value. Because the base type is not an object.

Execution Environment and scope

1, the implementation of the environment is the most important concept of JS. Each environment can search up the scope chain, but any environment cannot enter another execution environment by searching down the scope chain.

2. Declaring variables

Variables declared with Var are automatically added to the nearest environment, and within the function, the closest environment is the function's local function. In the With statement, the closest environment is the function environment. If you initialize a variable without using the var declaration, the variable is automatically added to the global environment.

var o = function () {        var a = ' 2 ';        return A;    };    Alert (typeof a);//undefined, there is no global access because it is defined inside a function, locally defined.    Alert (typeof A ());//

  

var A;    (function O () {        a = ' 2 ';        return A;    } ());    Alert (typeof a);//string,a is not declared with Var, so it is automatically added to the global, so you can access a

Query identifiers

  

If no identifier is found, it is searched globally until a stop query is found

  

Chapter fourth variables, scopes and memory issues (II)

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.