1
00:00:00,120 --> 00:00:04,740
I know we spent quite a bit of time on variables, and this is going to be the last lesson to wrap up

2
00:00:04,740 --> 00:00:10,860
some more information about variables and data types, because they are so super important as the fundamental

3
00:00:10,860 --> 00:00:15,540
core building block when you are programming, so when you are creating a variable.

4
00:00:15,570 --> 00:00:21,030
So as mentioned in the last lesson, when you first initialize it, it's initialized as undefined.

5
00:00:21,210 --> 00:00:26,370
And when you declare a value, declare a variable to it, then that doesn't necessarily mean that you're

6
00:00:26,370 --> 00:00:30,480
signing a value so you can do it independently or you can do it at the same time.

7
00:00:30,720 --> 00:00:33,480
So by default, it's undefined data type.

8
00:00:33,630 --> 00:00:38,550
And you can see that when you just declare the variable, such as test and output in the console's.

9
00:00:38,560 --> 00:00:41,330
We saw a little bit of that in the previous lesson as well.

10
00:00:41,640 --> 00:00:44,670
You can also declare multiple variables in one statement.

11
00:00:44,880 --> 00:00:49,500
So all we have to do is comma, separate them and these are all going to come out as undefined.

12
00:00:49,530 --> 00:00:51,890
So here we've got an example, really simple example.

13
00:00:51,900 --> 00:00:58,140
So we've got VAR A, B, C, D, or you could use left or const, but of course, const wouldn't make

14
00:00:58,140 --> 00:01:02,550
a whole lot of sense because then you're just declaring a bunch of variables that are supposed to stay

15
00:01:02,550 --> 00:01:03,560
as undefined.

16
00:01:03,810 --> 00:01:05,610
So not great use of cost.

17
00:01:05,710 --> 00:01:11,160
So more than likely you're either using VAR or left, and if you're programming with the six then you

18
00:01:11,160 --> 00:01:13,240
are more than likely using left for that one.

19
00:01:13,750 --> 00:01:20,850
Also the naming conventions so you don't have to use it as Camil case, but as you can see in this example,

20
00:01:21,120 --> 00:01:22,260
user first names.

21
00:01:22,260 --> 00:01:28,050
So when we do create variable names, we try to make them meaningful for what contents we're expecting

22
00:01:28,050 --> 00:01:28,680
to hold in them.

23
00:01:28,860 --> 00:01:34,410
And it makes it a whole lot easier to read your code down the line and also remember what all of these

24
00:01:34,410 --> 00:01:39,840
variables are doing and what information they're meant to be holding and the way that we do that because

25
00:01:39,840 --> 00:01:42,750
we can't include spaces in the variable name.

26
00:01:42,780 --> 00:01:48,090
Otherwise, you're going to throw an error the way that programmers will do this and they write multiple

27
00:01:48,270 --> 00:01:51,780
words and they patch them together using cavalcades.

28
00:01:52,020 --> 00:01:57,930
So the first word would just be lowercase and then the second word would be capitalized.

29
00:01:58,050 --> 00:02:00,500
So here we've got user and then first name.

30
00:02:00,510 --> 00:02:03,750
So first is capitalized and name is capitalized.

31
00:02:03,900 --> 00:02:08,120
Sometimes you might see first name all as just F capitalized.

32
00:02:08,250 --> 00:02:09,750
So all depending on the style.

33
00:02:09,840 --> 00:02:14,700
And this is the preferred way to name variables so that it's easier to read.

34
00:02:14,850 --> 00:02:21,300
And this is again from programming perspective when you are accessing your code and you've got a whole

35
00:02:21,300 --> 00:02:25,850
bunch of code and a whole bunch of lines of code, you're going to be really glad that you named them.

36
00:02:25,860 --> 00:02:31,980
Well, there's also when you are naming variables, you can use underscore you could use dollar signs

37
00:02:32,220 --> 00:02:35,210
and you could use letters and digits.

38
00:02:35,220 --> 00:02:38,100
The only thing is that they can't start with digits.

39
00:02:38,100 --> 00:02:44,670
They have to start with either one of these to underscore the dollar sign or a letter so it can't start

40
00:02:44,670 --> 00:02:45,270
with a digit.

41
00:02:45,780 --> 00:02:50,850
They can be upper and lower case, no spaces and it is case sensitive.

42
00:02:50,850 --> 00:02:57,060
So if you got a variable with all uppercase, it's going to be a different variable than with all lowercase.

43
00:02:57,360 --> 00:03:00,090
There's also no limit to the length of the variable name.

44
00:03:00,090 --> 00:03:05,760
But of course you want to keep it manageable and you don't want it having to be too long because variables,

45
00:03:05,760 --> 00:03:08,070
typically you're typing them quite often in the code.

46
00:03:08,190 --> 00:03:10,750
And trust me, you don't want to make them too long.

47
00:03:11,040 --> 00:03:12,960
There's also some reserved words.

48
00:03:12,960 --> 00:03:15,600
There's not a whole lot, but there are some reserved words.

49
00:03:15,600 --> 00:03:18,240
And this is available at the Mozilla Developer Network.

50
00:03:18,450 --> 00:03:21,480
So JavaScript reference lexical grammar.

51
00:03:21,660 --> 00:03:23,490
So these are the reserved words.

52
00:03:23,490 --> 00:03:29,880
So you can't call your variable const const or let let doesn't make a whole lot of sense and you've

53
00:03:29,880 --> 00:03:32,880
got to avoid these words and everything else is OK.

54
00:03:33,090 --> 00:03:36,680
There's also a future reserved words that you got to be mindful of.

55
00:03:37,200 --> 00:03:44,280
So when you are naming your variables, do take a quick glance at this and just to keep it in the back

56
00:03:44,280 --> 00:03:49,590
of your head that when you are naming your variables, that you don't name them as observed word.

57
00:03:49,740 --> 00:03:54,120
And if you do by mistake, then you're going to throw an error on that one.

58
00:03:55,770 --> 00:04:01,590
So the challenge for this lesson is to create some variables, update the values and output them into

59
00:04:01,590 --> 00:04:07,830
the console, and also use the code block for checking to see if a variable is true and output a message,

60
00:04:07,830 --> 00:04:10,020
a secret message into the console.

61
00:04:10,020 --> 00:04:13,670
And then you can change that to false and see if you get a different output.

62
00:04:13,860 --> 00:04:16,170
So very similar to what we did in the last lesson.

63
00:04:16,350 --> 00:04:22,530
But it is meant to get you to practice and get comfortable with variables and this time focus more on

64
00:04:22,530 --> 00:04:27,300
what the names of these variables are as they relate to the content that you're holding within them.

65
00:04:27,540 --> 00:04:33,270
And then also try the Campbell case so that you have different variables that might have longer names

66
00:04:33,270 --> 00:04:33,590
to them.

67
00:04:34,930 --> 00:04:38,910
So go ahead and pause the video and I'll show you the solution coming up.

68
00:04:38,920 --> 00:04:42,310
And here's a quick peek at the code snippet that we're going to be working with.

69
00:04:44,190 --> 00:04:48,990
So the first thing that we're going to do is declare a variable and we're going to assign a value of

70
00:04:48,990 --> 00:04:49,560
two to it.

71
00:04:49,590 --> 00:04:53,700
So this is going to be a concert that we're going to be using and then also declare a variable.

72
00:04:53,710 --> 00:04:54,780
So message.

73
00:04:55,060 --> 00:05:02,310
And here we can have a welcome message to the website and then also declaring a variable.

74
00:05:02,310 --> 00:05:04,560
But we're not going to have any content in it.

75
00:05:04,560 --> 00:05:11,050
And we're use Kemakeza in order to name that variable and we can cancel out the value of more stuff.

76
00:05:11,070 --> 00:05:12,150
So let's see what happens.

77
00:05:12,390 --> 00:05:15,740
And there's also another thing that you could do within the console.

78
00:05:15,870 --> 00:05:21,030
So if you do have variables, you can just simply type them into the console and you can see that instead

79
00:05:21,030 --> 00:05:26,970
of undefined, the response back from the browser is going to be the value that's being held within

80
00:05:26,970 --> 00:05:27,540
the variable.

81
00:05:27,750 --> 00:05:32,370
So, again, this is super useful when you are debugging your applications and you maybe want to know

82
00:05:32,370 --> 00:05:38,070
what a variable value is at a certain time, you can console log it out or you can go into the console

83
00:05:38,070 --> 00:05:39,140
and type the variable.

84
00:05:39,630 --> 00:05:43,800
So next, let's check to see if test is true.

85
00:05:44,160 --> 00:05:50,880
And if it is, then we're going to do something else so we can console, like the value of message and

86
00:05:50,880 --> 00:05:52,920
then also update more stuff.

87
00:05:52,930 --> 00:05:54,870
So we've got a bunch of stuff happening in here.

88
00:05:55,360 --> 00:05:57,690
So this can be whatever values you want to set.

89
00:05:57,690 --> 00:06:06,890
And then also we're going to set value of in block and this is secret within the block.

90
00:06:07,170 --> 00:06:12,720
So no, not much of a secret message, but you can use your creativity and your imagination to come

91
00:06:12,720 --> 00:06:15,190
up with something even more interesting than that.

92
00:06:15,210 --> 00:06:19,000
And of course, I'm sure you can and then just console that out.

93
00:06:19,020 --> 00:06:20,950
So let's try that out so we see that.

94
00:06:20,970 --> 00:06:22,030
Welcome to the website.

95
00:06:22,050 --> 00:06:23,830
This is the secret within the block.

96
00:06:23,850 --> 00:06:24,210
Yes.

97
00:06:24,210 --> 00:06:25,450
Content is here.

98
00:06:25,470 --> 00:06:30,300
So let's toggle this and let's switch this to force and refresh again.

99
00:06:30,420 --> 00:06:35,910
And you see that all we getting output is undefined because, of course, test isn't running because

100
00:06:35,910 --> 00:06:36,630
this is false.

101
00:06:36,870 --> 00:06:40,370
And all of this information is just within this block of code.

102
00:06:40,710 --> 00:06:42,990
So try to have some fun with the experiment.

103
00:06:43,170 --> 00:06:46,980
And coming up next, we're going to look at how to create interaction.

104
00:06:47,160 --> 00:06:52,140
So using the prompt where we can get information coming from the user and that's going to start with

105
00:06:52,290 --> 00:06:55,260
our user interaction and JavaScript.
