Javascript variable with example
what is a variable JavaScript
1] JavaScript variables are containers for storing information.
2] JavaScript store data value.
JavaScript Variable
1] var
2] let
3] const
1] var
1] JavaScript variables must identified with unique names.
2] Unique names call identifier.
3] identifier descriptive name is the (total volume, age, sum).
4] Creating a variable in JavaScript is declaring the variable.
Example :-
JavaScript Code :
var a= 10;
var b=20;
var c= a+b;
document.write(c);
Output :
2] let :-
1] let statement separate the variables by comma.
2] let can not be redeclared.
Example :-
JavaScript Code :
{ let value = 50;
document.write("Inside the function value = " + value); }document.write("<br> Outside the function value = " + value);
Output
{
let value = 50;
document.write("Inside the function
value = " + value);
}
document.write("<br> Outside the function value = " + value);
3] const :-
1] JavaScript const is keyword use declare a variable .
2] const variable cannot be reassigned a new value.
3] const keyword declare a variable do not change the value.
4] const variable creates only reference value.
Example :-
JavaScript Code :
const x = 90;
document.write("const variable value x = " + x);
Post a Comment