Theme Layout

Boxed or Wide or Framed

Wide

Theme Translation

Display Featured Slider

Featured Slider Styles

Display Grid Slider

yes

Grid Slider Styles

Display Trending Posts

Display Author Bio

Display Instagram Footer

off

Dark or Light Style

Light

Blog Archive

Powered by Blogger.

Friday, February 10, 2017

[JavaScript] Scope


# JavaScript Scope

Scope is the set of variables I have access to.

● JavaScript Scope

In JavaScript Scope, objects and functions are also variables.
In JavaScript, scope is the set of variables, objects, functions you have access to.
JavaScript has function scope: The scope changes inside functions.

● Local JavaScript Variables.

Variables declared within a JavaScript Function, become LOCAL to the function.
Local variables have local scope. They can only be accessed within the function.


Since local variables are only recognized inside their functions, variables with the same name can be used in different functions.
Local variables are created when a function starts, and deleted when the functions is completed.

● Global JavaScript Variables.

A variable declared outside a function, becomes GLOBAL.
A global variable has global scope. All scripts and functions on a web page can access it.

● Automatically Global

If you assign a value to a variable that has not been declared, it will automatically become a GLOBAL variable.
This code example will declare a global variable x, even if the value is assigned inside a function.


Do not create global variables unless you intend to. In "Strict Mode" automatically global variables will fall.

● Global Variables in HTML

With JavaScript, the global scope is the complete JavaScript environment.
In HTML, The global scope is the window object.
All global variables belong to the window object.


QuickEdit
Unknown
0 Comments
Share This Post :

You Might Also Like

No comments:

Post a Comment

Follow @SunriseSunsetBlog