1
00:00:00,200 --> 00:00:08,480
This is where we left in the previous video by explaining the syntax for writing JavaScript variables.

2
00:00:08,630 --> 00:00:14,120
In this video, let's get back to Visual Studio code and put them into code.

3
00:00:14,270 --> 00:00:21,860
I'm going to create a folder called Variables and I'm going to name this one according to the sections

4
00:00:21,860 --> 00:00:22,900
of this course.

5
00:00:22,910 --> 00:00:28,610
So here I'm going to name it as variables and you can name it whatever you want.

6
00:00:28,730 --> 00:00:37,970
And inside I'm going to create one HTML file and that is index dot HTML and let me scaffold it.

7
00:00:37,970 --> 00:00:45,470
And here I'm going to add H1 by saying JavaScript variables.

8
00:00:45,710 --> 00:00:56,780
And last step is I'm going to add the JavaScript file as script dot JS and I'm going to link up the

9
00:00:56,780 --> 00:01:04,950
JavaScript and I can use the script tag inside the head by using defer and that is what I'm going to

10
00:01:04,950 --> 00:01:05,600
use.

11
00:01:05,610 --> 00:01:14,040
So let me rename the title here as that and it's going to be a script and as we see.

12
00:01:15,260 --> 00:01:21,380
Dot script dot JS and I'm going to add defer.

13
00:01:21,410 --> 00:01:28,830
This is what we explained in the previous video how to connect or include JavaScript in HTML.

14
00:01:28,850 --> 00:01:37,700
So now let me collapse this one and this is my JavaScript file and let me open inside the browser and

15
00:01:37,700 --> 00:01:45,110
it has opened here as that and let me open the console right click inspect and there we go.

16
00:01:45,110 --> 00:01:53,240
And you can change the position of the console by clicking on this icon here and here you can toggle

17
00:01:53,270 --> 00:01:57,200
whether it should be below or on the other side.

18
00:01:57,740 --> 00:01:58,100
All right.

19
00:01:58,100 --> 00:01:59,270
So here we go.

20
00:01:59,270 --> 00:02:04,330
Let me close this once and have something like this and let me reload.

21
00:02:04,340 --> 00:02:04,760
Great.

22
00:02:04,760 --> 00:02:07,510
So now let's go ahead and explore more.

23
00:02:07,520 --> 00:02:13,370
So inside the script file, we are going to create our first variable.

24
00:02:13,370 --> 00:02:15,410
And it goes like this.

25
00:02:15,410 --> 00:02:17,660
It starts with the const.

26
00:02:17,690 --> 00:02:18,860
That is a keyword.

27
00:02:18,860 --> 00:02:25,100
So here we can begin with const or let or var.

28
00:02:25,550 --> 00:02:33,140
In this case, we are going to save a name of a person inside our application.

29
00:02:33,350 --> 00:02:35,090
So it goes like this.

30
00:02:35,090 --> 00:02:47,210
So here I'll add a comment by saying variable declaration and for this we can begin using the let keyword

31
00:02:47,300 --> 00:02:49,880
or var or const.

32
00:02:49,910 --> 00:02:53,120
I will show you when to use one of these.

33
00:02:53,120 --> 00:03:02,360
So the whole logic here is that we are going to save an age of a person inside our application and I'm

34
00:03:02,360 --> 00:03:11,150
going to use Var for this and it follows the name of the variable and I will say age and I will assign

35
00:03:11,150 --> 00:03:14,000
to the value, let me say 20.

36
00:03:14,570 --> 00:03:15,050
Great.

37
00:03:15,050 --> 00:03:24,900
So now if you go ahead and console log the age, we're going to have the value of 20, meaning that

38
00:03:24,930 --> 00:03:33,630
we have saved 20 inside the age and JavaScript internally have saved this variable.

39
00:03:33,780 --> 00:03:43,410
So if I save this file and back to Chrome and if I make use of age now, let's see.

40
00:03:46,010 --> 00:03:54,320
Now, as you can see, we have 20 meaning that JavaScript internally have saved the value that we have

41
00:03:54,320 --> 00:03:57,680
declared in its internal memory.

42
00:03:57,800 --> 00:04:06,110
And again, I can go ahead and console log the age and inside the console here.

43
00:04:06,110 --> 00:04:07,340
Let me refresh it.

44
00:04:07,340 --> 00:04:11,330
As you can see, we have the 20 down here.

45
00:04:11,360 --> 00:04:14,900
Let me remove the one that we just did.

46
00:04:14,900 --> 00:04:25,370
And if I refresh it, as you can see, we have 20 and I can declare a variable, let's say let and I'm

47
00:04:25,370 --> 00:04:32,720
going to use, let's say, money and is equal to $100.

48
00:04:32,720 --> 00:04:43,160
And if I console dot log the money here, we're going to have $100 and I can use const, let me say

49
00:04:43,160 --> 00:04:51,470
const and I will say city is equal to Kumar C for string.

50
00:04:51,470 --> 00:05:00,830
Put them inside quote and I will show you how we can declare variables in the recommended ways.

51
00:05:01,040 --> 00:05:01,430
All right.

52
00:05:01,430 --> 00:05:06,890
So with this one, if I save it and console log the city.

53
00:05:06,920 --> 00:05:08,450
Now let's have a look.

54
00:05:08,480 --> 00:05:11,630
And indeed we have it down here.

55
00:05:11,780 --> 00:05:12,290
Great.

56
00:05:12,290 --> 00:05:15,500
So, guys, this is how we declare a variable.

57
00:05:15,530 --> 00:05:22,760
The takeaway here is that no, the keyword and then the variable name and then the value.

58
00:05:22,790 --> 00:05:27,230
Don't worry, we're going to have best practices for declaring variables.

59
00:05:27,230 --> 00:05:29,240
And this is the starting point.

60
00:05:29,270 --> 00:05:31,340
Let's continue in the next video.

