Variables in JavaScript

In this tutorial, we will check variables in JavaScript. If you learnt any programming language before then you would have an idea what these variables are. For those who never heard this word before variables are simply named of storage locations. Meanwhile working on any program we store some values in different memory locations and variables simply reference to these memory locations and allow us to fetch values from these memory locations.

There are some rules as other languages while writing the identifiers of these variables.

  • Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
  • After first letter we can use digits (0 to 9), for example value1.
  • JavaScript variables are case sensitive, for example name and Name are different variables.

Some valid variable names:

var x = 10;  

var min_age="18;  

var name="Owlbuddy";

Difference Between Local and Global Variables:

Local Variables: 

Variables which we declare inside a block or inside a function are known as a local variable and where these variable are declared only that function or block can use these variables.

function show(){  
var name="owlbuddy";//local variable  

Global Variables:

Variables which we declare outside of the block or any function are known as global variables and these can use from anywhere in code.

var name="owlbuddy";//gloabal variable  
function show1(){  
function show2(){  


Spread the love:

Please share this page on social media with your friends..

Facebook share Twitter Linkedin share

Great News! Now you can read all the tutorials on our Android App..

Download Owlbuddy: Learn Programming Tutorials App Now.

Download Owlbuddy: Learn Programming Tutorials