[Go to site: main page, start]

0% found this document useful (0 votes)
5 views2 pages

JavaScript Variables

The document explains JavaScript variables, defining them as containers for values and outlining the syntax rules for naming variables. It describes four ways to declare variables: automatically, using var, let, and const, and highlights the differences between var, let, and const regarding scope and mutability. Examples of variable declaration and usage are provided for each method.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

JavaScript Variables

The document explains JavaScript variables, defining them as containers for values and outlining the syntax rules for naming variables. It describes four ways to declare variables: automatically, using var, let, and const, and highlights the differences between var, let, and const regarding scope and mutability. Examples of variable declaration and usage are provided for each method.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

❖​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

You might also like