WEBVTT

1
00:00:00.080 --> 00:00:01.220
Welcome to this video.

2
00:00:01.240 --> 00:00:05.300
Today we're going to dive into the basics
of next generation JavaScript syntax.

3
00:00:05.330 --> 00:00:08.900
var is an outdated syntax
for creating a new variable.

4
00:00:08.930 --> 00:00:12.010
From now on, we'll be using let instead.

5
00:00:12.040 --> 00:00:16.460
So let's change up our variables to let

6
00:00:16.490 --> 00:00:23.780
here. Let creates a variables, but its
scoping behavior is different from var.

7
00:00:23.810 --> 00:00:28.415
If we want to create variable
that never changes, we use const keyword.

8
00:00:28.615 --> 00:00:30.380
Const creates a constant

9
00:00:30.400 --> 00:00:35.100
which makes it clear in the code that the
value of that variable will never change.

10
00:00:35.130 --> 00:00:37.820
For example,
if we are planning on assigning a new

11
00:00:37.850 --> 00:00:42.940
value to age, then we can
let it be a let variable.

12
00:00:42.970 --> 00:00:47.380
But if we never change our name,
then we can make it constant.

13
00:00:47.410 --> 00:00:50.220
If we try to set name to something else

14
00:00:50.240 --> 00:00:52.940
and run the code,
we're going to get an error because we're

15
00:00:52.970 --> 00:00:56.380
trying to assign a value
to a constant variable.

16
00:00:56.410 --> 00:00:59.740
So let's try to reassign the name here

17
00:00:59.770 --> 00:01:04.490
and let's say that I wanted to
have a value of my full name.

18
00:01:04.520 --> 00:01:07.960
If I try to run this code,

19
00:01:08.040 --> 00:01:12.850
we're getting an error saying:
assignment to constant variable.

20
00:01:12.880 --> 00:01:17.770
The idea behind const is to use it as
often as possible to make it clear

21
00:01:17.800 --> 00:01:19.639
in the code what's happening

22
00:01:19.839 --> 00:01:21.740
if something should never change

23
00:01:21.770 --> 00:01:26.140
make it a const so that you get
an error if you accidentally change it.

24
00:01:26.160 --> 00:01:28.280
Thanks for watching and see
you in the next video.

