30
Variables and constants in JS
Variables are like storage containers and are hence used to store data to facilitate a web app to run better.
To declare a variable we use
(You may see variables being declared using the
To declare a variable we use
let
keyword as follows:let name = "Sumit"
(You may see variables being declared using the
var
keyword but using let
is newer way and better practice).name
' which is currently storing 'Sumit'. We can now store any new data in that same variable called name
like:
name = "Paris"
. Now our variable is storing new data called "Paris" instead of the old "Sumit".
let recipeName = "London"
😅
let
, const
etc and these shouldn't be used as variable namesConstants are variables that can't change their values once assigned i.e., after we assign some value to a constant, we can't assign new value or in other words they are constant (hence the name!).
They are declared using the keyword
They are declared using the keyword
const
as shown in the image below:
If we now try to re-assign a value to a constant, we'll get an error like:

That's it for today folks. This is an ongoing series of articles, so stay tuned for more.
Also, since you're reading till here, I'm assuming you found this to be of value, so please like this article and share it with your friends and as always drop your comments down below.
Also, since you're reading till here, I'm assuming you found this to be of value, so please like this article and share it with your friends and as always drop your comments down below.
~ Sumit Saurabh.
30