JS_coder

JS variables

JS variables

A 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.
}
xyz()

::output : 2

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

How do you rate this article?

0


RahulWeb-Dev
RahulWeb-Dev

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


JS_coder
JS_coder

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

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?