JS variables

JS variables

By RahulWeb-Dev | JS_coder | 18 Dec 2020

JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable.

JavaScript Variables are also known as identifiers.

First hand rules when you declare a variable :-

1. JS variables are case sensitive(x and X are different).

2.Name must start with a letter,underscore or dollar sign.

3.After first letter,we can use numbers.(javascript1).

Correct way : -

var x =  10;
var_value = 'Any'


JavaScript local variables :-

A JavaScript local variable is declared inside block or function. It is accessible within the function or block only.

function xyz() {
var a = 10 //local var

 Global Variables :-

Global variable can be accessible from any function.It is declared outside function or with the window object.


var cat = 2
function xyz() {
console.log(cat) //Console.log is used to log the data inside the console.

::output : 2

For console go to chrome developer tools(in settings) and go to console from there.(Try to console.log this function)


Cryptoenthusiast and on the way to become a Web-Developer.


Learn JavaScript and know more about it ,how it works and its frameworks.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.