1
00:00:00,880 --> 00:00:07,090
You've seen brief glimpses of them before in the earlier lessons, they're variables and they're used

2
00:00:07,090 --> 00:00:14,050
all over the place in programming, they're one of the four core fundamentals of any programming, language

3
00:00:14,380 --> 00:00:15,290
and a variable.

4
00:00:15,340 --> 00:00:20,340
What it is, is it's allows you to hold information in a value.

5
00:00:20,710 --> 00:00:26,950
So if you're typing out a really long paragraph, like I really, really enjoy working with JavaScript

6
00:00:27,400 --> 00:00:33,580
and you want to have that message and maybe even update that message, well, the best place to place

7
00:00:33,580 --> 00:00:34,990
it is within a variable.

8
00:00:35,110 --> 00:00:42,400
And then you can reference it just by using variable message and then you can always get that information

9
00:00:42,400 --> 00:00:43,660
back in.

10
00:00:43,660 --> 00:00:49,710
Variables are assigned so they can assign values to them by using the equal sign.

11
00:00:50,020 --> 00:00:54,880
So variables when we are trying to use them, you need to declare them as well.

12
00:00:55,150 --> 00:00:59,440
And in order to declare a variable, that's where that var came in.

13
00:00:59,680 --> 00:01:06,030
And we did see this earlier where we were declaring variables of A, B, C and so on.

14
00:01:06,040 --> 00:01:09,070
So we're using variable X to equal one.

15
00:01:09,250 --> 00:01:11,470
So they could be numbers, they can be strings.

16
00:01:11,470 --> 00:01:13,900
And there's more on this coming up in the upcoming lessons.

17
00:01:14,260 --> 00:01:20,140
So for now we can see that we've got a variable we can console logout its value.

18
00:01:20,150 --> 00:01:22,590
So referencing the variable by the name.

19
00:01:22,840 --> 00:01:29,980
So if we want to set a variable X to equal one, then we can use console log and return back that variable

20
00:01:29,980 --> 00:01:32,080
value just by referencing X.

21
00:01:32,380 --> 00:01:38,590
And then we can also update the value that's contained for X and we can set it to two or whatever value

22
00:01:38,590 --> 00:01:39,130
we want.

23
00:01:39,400 --> 00:01:45,400
And in JavaScript it's dynamic typing so we can switch between different types so we can have numbers

24
00:01:45,400 --> 00:01:46,030
and strings.

25
00:01:46,240 --> 00:01:48,790
And of course, more on this later on in the lesson.

26
00:01:48,840 --> 00:01:53,740
So there's a quick challenge for you in this lesson and that's to declare a variable.

27
00:01:53,920 --> 00:02:02,200
You can use a simple variable name such as ABCDE e whatever you want, and then or you could call it

28
00:02:02,200 --> 00:02:09,940
message and then update that value to a new message and then also declare a variable that holds your

29
00:02:09,940 --> 00:02:14,680
name and then change it to your friend's name and output it in the console.

30
00:02:15,010 --> 00:02:16,050
So that's the challenge.

31
00:02:16,060 --> 00:02:18,310
And there's a code snippet to go along with this.

32
00:02:18,610 --> 00:02:26,020
So you can see that we're first starting out by console, logging out the value of a as so setting it

33
00:02:26,020 --> 00:02:28,120
as hello world and logging it out.

34
00:02:28,300 --> 00:02:33,640
And then we've got welcome back and we're logging out that variable of eight again and we're going to

35
00:02:33,640 --> 00:02:39,100
see it's got a different message and then we're setting a name and we're console logging out the name

36
00:02:39,100 --> 00:02:43,230
and then we're setting the name of our friend and we're console logging out that name.

37
00:02:43,240 --> 00:02:48,640
So let's try that out so we can pause the video here and write the code opening brackets.

38
00:02:49,060 --> 00:02:51,340
First, we're going to declare a variable.

39
00:02:51,340 --> 00:02:54,400
So we're going to just use a as a basic variable.

40
00:02:54,400 --> 00:02:57,430
And there are some rules which we are going to be covering later on.

41
00:02:58,090 --> 00:03:01,900
So setting the variable value of a two hello world.

42
00:03:02,050 --> 00:03:06,970
And now if I go into the console, if I type out A, I can see how the world gets returned back.

43
00:03:07,150 --> 00:03:12,490
And if I want to see it directly within the console without having to type A, I can console log that.

44
00:03:12,610 --> 00:03:16,030
And when I refresh, I see how the world is written in my console.

45
00:03:16,510 --> 00:03:20,440
So the objective of this lesson was also to assign a new value to a.

46
00:03:20,650 --> 00:03:24,010
So once I've declared a I don't have to redeclared again.

47
00:03:24,190 --> 00:03:30,820
So I'm not using VAR again because that information is contained already within the variable of a so

48
00:03:30,820 --> 00:03:34,610
I don't have to declare it again, but I can reassign values with the equals sign.

49
00:03:34,630 --> 00:03:41,530
So this is just that one equals sign and we want it to write in a usage of welcome back to that value

50
00:03:41,530 --> 00:03:45,560
of eight and then logging out the console message one more time.

51
00:03:45,910 --> 00:03:52,180
So now you can see that initially when we come in, the value of a hello world and then next time we

52
00:03:52,180 --> 00:03:55,950
output the value of a it's changed to welcome back.

53
00:03:55,960 --> 00:04:00,990
And there is a second part to this challenge that was to create a name.

54
00:04:01,000 --> 00:04:09,700
So giving your name within the variable value and console, logging out that my name variable and then

55
00:04:09,700 --> 00:04:14,320
taking the my name variable and assigning a new value to it.

56
00:04:14,350 --> 00:04:20,500
So in this case, I'm going to sign it to John and then once again console logging out my name variable

57
00:04:20,740 --> 00:04:22,360
and seeing the changes.

58
00:04:22,750 --> 00:04:27,880
So you can see that we were able to declare the variable with the value, assigning a value to it as

59
00:04:27,880 --> 00:04:28,570
we declared it.

60
00:04:28,810 --> 00:04:33,070
And then we updated the value and we have different values coming back in the output.

61
00:04:33,100 --> 00:04:37,240
So coming up next, there is a little bit more information on variable, so we need to cover.

62
00:04:37,420 --> 00:04:38,170
That's still to come.
