1
00:00:00,180 --> 00:00:01,380
In this video.

2
00:00:01,380 --> 00:00:04,560
Let's talk about block scope.

3
00:00:04,740 --> 00:00:05,970
So let me comment.

4
00:00:05,970 --> 00:00:07,110
This one's.

5
00:00:10,150 --> 00:00:13,150
Copy this one down here.

6
00:00:13,180 --> 00:00:18,220
I'm going to be as block scope in JavaScript.

7
00:00:18,220 --> 00:00:25,630
BLOCK scope refers to the visibility of variables within a code block, and the code block is a set

8
00:00:25,630 --> 00:00:29,530
of carry braces that encloses one or more statements.

9
00:00:29,560 --> 00:00:30,520
So let's see.

10
00:00:30,520 --> 00:00:32,830
So let's declare a variable.

11
00:00:32,860 --> 00:00:33,670
Let's.

12
00:00:35,120 --> 00:00:37,910
H equal to 30.

13
00:00:38,760 --> 00:00:48,630
And now let's use if statement to create code block and here we go if and then my code block so whatever

14
00:00:48,630 --> 00:00:55,110
I declare inside the code block, it becomes what my block scope let's see.

15
00:00:55,110 --> 00:01:01,080
So let's say that if the age above because this in a global scope I can access it here.

16
00:01:01,080 --> 00:01:02,190
So if.

17
00:01:03,240 --> 00:01:06,210
So if H is.

18
00:01:07,000 --> 00:01:13,080
More than 18 years and we can say that you are old enough.

19
00:01:13,090 --> 00:01:19,150
So let's also declare a variable core message which is equal to you.

20
00:01:20,240 --> 00:01:23,210
Are old enough.

21
00:01:23,450 --> 00:01:23,990
Great.

22
00:01:23,990 --> 00:01:28,040
And now we can console.log the message.

23
00:01:28,930 --> 00:01:30,490
And that, so let's save it.

24
00:01:30,490 --> 00:01:35,560
And now indeed you are old enough, but here is a clue.

25
00:01:35,950 --> 00:01:44,560
Remember that we have declared a variable called age in a global scope and line number 31.

26
00:01:44,560 --> 00:01:49,030
We also declare a variable called message inside a code block.

27
00:01:49,030 --> 00:01:52,660
So now this variable is in a block scope.

28
00:01:52,660 --> 00:01:57,490
I cannot access this outside my block scope.

29
00:01:57,520 --> 00:02:04,000
Let's see if I try to console that, log the message inside my code block.

30
00:02:04,000 --> 00:02:06,520
Let's see I get an error.

31
00:02:06,910 --> 00:02:15,940
This means that this message is in scope to this code block here, but if I try to access it, I can

32
00:02:15,940 --> 00:02:20,020
still access it because it is in a global scope.

