Variables in JavaScript

Variables are just like a container. Like many other programming languages, JavaScript has variables. You can place data into these containers and then refer to the data simply by naming the container.

Example of JavaScript variables

<script type = "text/javascript">
var name = "Ali";
var money;
money = 2000.50;

JavaScript Variable Scope

The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes.

Global Variables

A global variable has global scope which means it can be defined anywhere in your JavaScript code.

Local Variables

A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable. Take a look into the following example.

JavaScript Reserved Words

Character Description Name Number
byte abstract boolean break
case catch char class
const continue debugger default
delete do double else
enum export extends false
final finally float for
function goto if implements
import in instanceof int
interface long native new
null package private protected
public return short static
super switch synchronized this
throw throws transient true
try typeof var void
volatile while with

The Best

Comment here

If you have any query, if you want to know something about any of technical course related to computer science field, if you have any suggestion about relevant to uploaded content or if you anything wrong here (any mistake in content) than please contact us. Keep in mind, comment should be according to community guidelines.