Content Menu

Home-What is JavaScript?

JavaScript tutorials

1. JavaScript Basics

2. JS Simple Coding

3. JS InterActive Content

4. Images and JS

5. JS Functions

6. JavaScript Events

7. JS Conditional

8. JS Loops

9. Other

JavaScript Variable Types by Scope

Another way variables are classified in Javascript are by Scope. i.e. whether the variable is usable only within a function or throughout the whole page.

The two types are

  1. Local Variable
  2. Global Variable

Local Variable

A local variable is one that is declared / Created within a function in Javascript. It is usable only within that function, in other words has a local scope. Such variables are deleted, once the function has been executed.

Global Variable

All the variables that are not declared within a function are called Global variables. Can be used anywhere throughout the page and any function or other code can alter its value i.e. they have a global scope.

Prev- JavaScript While Loop