❖JavaScript Variables
● The set of rules to follow while writing a JavaScript
program is called JavaScript syntax.
:-- What is a Variable?
● The variable is a container that has a value.( Example:-
this is similar to the containers used to store
vegetables , fruits , and rice.)
:-- Rules of choosing variable names
● Letters, digits , underscores & ($) sign allowed.
● Javascript reserved words cannot be used as a variable
name.
:-- JavaScript Variables can be declared in 4 ways
● Automatically
● Using var
● Using let
● Using const
:--Difference between var, let and const?
● Var is globally scoped while let & const are block scoped.
● Var can be an Updated & re-declared variable.
● Let can be updated but not re-declared.
● Const can neither be updated nor be re-declared.
● Only use var if you must support old browsers.
1.Automatically:-
X = 10
Y = 20;
Z = X + Y;
2.Using Var :-
Var name = “sam”;
[Link](name); output= sam
3.Using let :-
Let a = 10;
Let b = 20;
Let c = a+b
[Link](“the sum of two number”, c); output=30
4.Using const :-
Const x = 10;
[Link](x); output=10