Scope Introduction - Essential JavaScript Concepts
If you are planning to accelerate your career as JavaScript Professional, you must know some basic JavaScript concepts. Here in our video tutorials we have explained relevant and important JS concepts which are picked based on popularity among the JavaScript communities. Each and every concept is covered in depth and with clarity. They are described with help of real world scenarios so that you can learn these core JavaScript concepts in just few minutes.
Let’s start with first concept - Scope. It is nothing but the accessibility of variables, functions, and objects in some particular part of your code during run-time. In other words, scope determines the visibility of variables and other resources in areas of your code. Scope is simply a box with boundaries. Traditionally, JavaScript has two types of scope:
Global Scope: Variables are known throughout the application, from the start of the application.
Functional Scope: Variables are known within the function they are declared in, from the start of the function.
Scope determines the accessibility (visibility) of these variables. Variables defined inside a function are not accessible (visible) from outside the function. Variables declared within a JavaScript function, become LOCAL to the function. Local variables have Function scope; they can only be accessed from within the function. 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. Please visit our video session JavaScript Concepts: Scope | 0004-01 to know more in detail.