Welcome to this video.
Today we're going to dive into the basics of next generation JavaScript syntax.
var is an outdated syntax for creating a new variable.
From now on, we'll be using let instead.
So let's change up our variables to let
here. Let creates a variables, but its scoping behavior is different from var.
If we want to create variable that never changes, we use const keyword.
Const creates a constant
which makes it clear in the code that the value of that variable will never change.
For example, if we are planning on assigning a new
value to age, then we can let it be a let variable.
But if we never change our name, then we can make it constant.
If we try to set name to something else
and run the code, we're going to get an error because we're
trying to assign a value to a constant variable.
So let's try to reassign the name here
and let's say that I wanted to have a value of my full name.
If I try to run this code,
we're getting an error saying: assignment to constant variable.
The idea behind const is to use it as often as possible to make it clear
in the code what's happening
if something should never change
make it a const so that you get an error if you accidentally change it.
Thanks for watching and see you in the next video.