1
00:00:00,540 --> 00:00:01,110
Welcome back.

2
00:00:01,140 --> 00:00:07,500
We're now on lesson two of Section three, single line and multiline commenting type coercion and variable

3
00:00:07,500 --> 00:00:08,100
mutation.

4
00:00:08,370 --> 00:00:11,850
First thing, we're going to talk about a single line and multiline comments and then we'll come back

5
00:00:11,850 --> 00:00:15,690
to this and talk about coercion and variable mutation.

6
00:00:16,500 --> 00:00:19,620
It's best practice to use comments frequently to document your code.

7
00:00:20,190 --> 00:00:25,710
It's also extremely useful for commenting about code you're not sure is working properly or to test

8
00:00:25,710 --> 00:00:26,610
various versions.

9
00:00:27,390 --> 00:00:28,460
So let's take a look at our code.

10
00:00:29,400 --> 00:00:34,830
So as you recall from our last lesson, we looked at this example of the global execution context.

11
00:00:34,860 --> 00:00:37,260
So how could we document this further?

12
00:00:37,260 --> 00:00:42,450
How could we do a better job explaining this here and cleaning this up?

13
00:00:43,350 --> 00:00:46,690
OK, so let's make sure this is going to the right one.

14
00:00:47,220 --> 00:00:52,710
So one thing we could do is add a single line comment and the way we do that is with two forward slashes.

15
00:00:54,480 --> 00:00:58,890
And you could also do a controlled forward slash toggle between comments and not comments.

16
00:01:00,220 --> 00:01:09,610
And we could explain this is the global execution context, so this is a form of documentation context

17
00:01:10,180 --> 00:01:16,120
so we can explain to the reader of this code what we're trying to explain here.

18
00:01:17,500 --> 00:01:20,410
And then we could jump in here and say.

19
00:01:24,270 --> 00:01:27,030
Function, execution context.

20
00:01:30,860 --> 00:01:39,980
OK, and we can go down here and instead of having these two lines, which they're really kind of sequential,

21
00:01:40,490 --> 00:01:42,530
let's do a multiline comment.

22
00:01:42,920 --> 00:01:52,100
So the way we do multiline comments is with a forward slash asterisk and then we can say eval execution

23
00:01:53,390 --> 00:01:54,140
context.

24
00:01:56,830 --> 00:02:04,000
And then when we have multiline comments, we don't actually need to have the original double line comments

25
00:02:04,000 --> 00:02:07,270
anymore, we just need to end it with one of those.

26
00:02:07,720 --> 00:02:11,170
And so these could be just on their own separate lines.

27
00:02:12,460 --> 00:02:18,120
Multiline comments are nice, especially when you have a long paragraph that you want to document,

28
00:02:18,790 --> 00:02:26,950
some people would like to do this with multiline comments just so that all the lines are indented to

29
00:02:26,950 --> 00:02:27,670
the same degree.

30
00:02:27,850 --> 00:02:28,870
Definitely up to you.

31
00:02:29,620 --> 00:02:31,840
But the purpose here would be to.

32
00:02:33,430 --> 00:02:40,330
Comment something out that is multiple lines, and especially for documentation purposes, if you have

33
00:02:40,330 --> 00:02:44,920
a long paragraph that you'd like to comment out and break it down into multiple lines, you can certainly

34
00:02:44,920 --> 00:02:46,470
do so with a multiline comment.

35
00:02:46,600 --> 00:02:51,760
So that's a forward slash asterisk and end it with an asterisk forward slash.

36
00:02:51,970 --> 00:02:52,840
So that's how you do it.

37
00:02:53,020 --> 00:02:57,850
There's a very similar process that works in HTML as well with a multiline comment.

38
00:02:59,660 --> 00:03:06,890
OK, so that is single line commenting and multiline commenting and what's nice about single line commenting

39
00:03:06,890 --> 00:03:12,170
is it's easy to toggle those on and off to test individual lines of code.

40
00:03:12,410 --> 00:03:17,230
But now let's get into the next section of this, which is type coercion.

41
00:03:18,980 --> 00:03:20,360
So let's learn about type coercion.

42
00:03:21,560 --> 00:03:27,170
Now, the purpose of coercion is just that JavaScript automatically converts numbers and booleans to

43
00:03:27,170 --> 00:03:31,490
strings during concatenation with the plus operator and strings.

44
00:03:32,240 --> 00:03:33,180
That's a lot of information.

45
00:03:33,200 --> 00:03:34,910
Let's take that piece by piece.

46
00:03:35,330 --> 00:03:44,720
OK, JavaScript is going to automatically turn numbers and true or false values into text during the

47
00:03:44,720 --> 00:03:50,570
process of adding these pieces of information together in a line of text.

48
00:03:51,090 --> 00:03:53,750
OK, so let's look at an example.

49
00:03:54,530 --> 00:04:00,050
Now, the reason this is important to note is that we need to understand that certain pieces of data

50
00:04:00,050 --> 00:04:04,910
are just going to be read and understood a little bit differently depending on the way that they're

51
00:04:04,910 --> 00:04:05,330
used.

52
00:04:06,170 --> 00:04:07,220
So let's start with.

53
00:04:08,540 --> 00:04:17,900
Let and let's just set up these three variables, OK, and what's happening here is something called

54
00:04:17,900 --> 00:04:18,770
declaration.

55
00:04:18,770 --> 00:04:22,450
We're going to get into that in the next lesson a little bit more.

56
00:04:22,490 --> 00:04:24,690
We just did a declaration of multiple variables.

57
00:04:24,710 --> 00:04:26,900
Now we're going to assign them some values.

58
00:04:28,890 --> 00:04:29,540
So let's just see.

59
00:04:29,540 --> 00:04:35,780
This animal is a dog and let's do is hungry.

60
00:04:40,630 --> 00:04:45,460
OK, make sure that you're using the same variable names that you've already set up, if you have a

61
00:04:45,460 --> 00:04:47,380
typo, it's not going to understand it.

62
00:04:49,060 --> 00:04:51,970
And of this new age equals 12.

63
00:04:53,080 --> 00:04:56,790
OK, so as you can see, we have three variables here.

64
00:04:56,800 --> 00:04:58,630
Animal is hungry and age.

65
00:04:59,980 --> 00:05:04,980
And with this one noticed that the second word has an uppercase letter, this is called Camil Case,

66
00:05:05,800 --> 00:05:10,850
and it's just a very nice way to be able to read a variable name that has multiple words in it.

67
00:05:11,230 --> 00:05:15,340
So this is a standard across a lot of programming languages.

68
00:05:15,680 --> 00:05:21,370
There are other ways to make variables easy to read if they have multiple words like snake case.

69
00:05:22,580 --> 00:05:23,480
Which is like that.

70
00:05:24,780 --> 00:05:30,970
Kabab case, which is like that, but the preferred way for variable names in JavaScript is camel camel

71
00:05:30,990 --> 00:05:31,650
case like this.

72
00:05:32,200 --> 00:05:35,760
OK, so we've got these three variables.

73
00:05:35,760 --> 00:05:41,280
We've assigned values to them and notice that this one looks different than this one and looks different

74
00:05:41,280 --> 00:05:41,800
than that one.

75
00:05:41,850 --> 00:05:52,260
That's because this is a string and this is a boolean, which means it's a true or false value and this

76
00:05:52,260 --> 00:05:52,940
one is a number.

77
00:05:54,330 --> 00:05:56,940
So obviously, this looks like a line of text.

78
00:05:57,450 --> 00:05:58,230
It's in quotes.

79
00:05:58,950 --> 00:05:59,940
This looks like a number.

80
00:06:00,120 --> 00:06:03,030
And this looks like it's not exactly the same as this.

81
00:06:03,220 --> 00:06:06,810
It's not a line of text as understood by JavaScript.

82
00:06:06,810 --> 00:06:07,580
It's not a string.

83
00:06:08,190 --> 00:06:11,910
It's a special keyword that indicates that something is true.

84
00:06:12,360 --> 00:06:18,810
So this type coersion right now that we're going to get into is to show you what happens when we automatically

85
00:06:19,380 --> 00:06:20,430
push these together.

86
00:06:22,310 --> 00:06:23,540
So let's console log.

87
00:06:27,320 --> 00:06:27,950
My.

88
00:06:31,170 --> 00:06:38,280
And then we use the plus to concatenate concatenation means we're going to glue multiple texts together

89
00:06:39,450 --> 00:06:44,010
and then we don't need to put the variable in quotes, we just say the name of the variable and that's

90
00:06:44,010 --> 00:06:46,380
going to execute or invoke that variable.

91
00:06:47,670 --> 00:06:49,980
And then we do is.

92
00:06:53,050 --> 00:06:56,830
So so far, what is that going to say that's going to say?

93
00:06:58,670 --> 00:06:59,930
My dog is.

94
00:07:01,320 --> 00:07:02,160
Let's add.

95
00:07:04,370 --> 00:07:10,310
Age and then add years old.

96
00:07:13,210 --> 00:07:18,370
Now, one thing I got to make sure of is that I have spaces in here because it's not going to add the

97
00:07:18,370 --> 00:07:19,690
spaces automatically for me.

98
00:07:21,500 --> 00:07:25,880
OK, so now we've got spaces and then let's add.

99
00:07:29,130 --> 00:07:31,940
OK, so we went ahead and saved that and let's test it out.

100
00:07:34,010 --> 00:07:41,600
My dog is 12 years old, so interesting just to note that even though 12 is a number, it changed,

101
00:07:41,600 --> 00:07:44,060
it coerced, so it forced.

102
00:07:45,000 --> 00:07:52,830
The number 12 to be understood as a different type, so the string is one type booleans and other type

103
00:07:52,960 --> 00:07:58,860
numbers, another type, so we can actually force a Boolean to act like a string or force a number to

104
00:07:58,860 --> 00:08:04,890
act like a string if we can cat need it in strings so we can actually cancel log.

105
00:08:09,480 --> 00:08:10,710
We could do if.

106
00:08:16,850 --> 00:08:18,050
If is hungry.

107
00:08:27,250 --> 00:08:28,420
Then council log.

108
00:08:34,820 --> 00:08:35,510
My.

109
00:08:38,720 --> 00:08:41,060
Animal is.

110
00:08:47,730 --> 00:08:48,270
Hungry?

111
00:08:52,990 --> 00:08:58,960
So we have this conditional expression happening right here where we're saying, if my dog is hungry.

112
00:09:00,150 --> 00:09:07,130
Then print out, my dog is hungry, is hungry, is true, OK, in this case it is true.

113
00:09:07,350 --> 00:09:09,190
So it should print out to the console.

114
00:09:09,390 --> 00:09:10,290
My dog is hungry.

115
00:09:12,020 --> 00:09:12,660
And there you go.

116
00:09:12,710 --> 00:09:21,530
It worked, my dog is 12 years old and my dog is hungry, so that's what we did to coerce the type of

117
00:09:21,530 --> 00:09:24,680
12th and true to be acting as.

118
00:09:25,460 --> 00:09:27,260
So let's just test to see what happens.

119
00:09:27,260 --> 00:09:32,630
If we say our dog is hungry, we could say it's

120
00:09:36,950 --> 00:09:37,610
true.

121
00:09:46,280 --> 00:09:46,940
He's hungry.

122
00:09:54,890 --> 00:10:00,020
OK, so now we're going to see what happens when we refresh.

123
00:10:04,830 --> 00:10:11,370
So because it is hungry, we made this conditional expression in this if statement and said, if hungry

124
00:10:11,370 --> 00:10:16,260
is true, then council log, it's plus true.

125
00:10:17,230 --> 00:10:18,990
Plus, he's hungry.

126
00:10:20,380 --> 00:10:27,430
So it turned out is true right here, which is a special word, it's not a string into a string because

127
00:10:27,430 --> 00:10:29,320
we can cat needed with strings.

128
00:10:31,190 --> 00:10:34,760
All right, so that is type coersion.

129
00:10:36,080 --> 00:10:41,030
Variable mutation is the simple idea that you can take this and change the value.

130
00:10:41,900 --> 00:10:45,320
Now, if I want my age to be 13, I could do that.

131
00:10:46,140 --> 00:10:47,720
And that is the variable

132
00:10:50,900 --> 00:10:51,640
mutation.

133
00:10:54,500 --> 00:10:55,970
And if I change is hungry.

134
00:10:59,840 --> 00:11:00,470
To false.

135
00:11:03,830 --> 00:11:05,330
Now, if I try to run this again.

136
00:11:09,370 --> 00:11:11,040
Do you expect it to run a second time?

137
00:11:12,070 --> 00:11:12,580
Let's see.

138
00:11:16,170 --> 00:11:17,700
Now, it only ran once.

139
00:11:18,360 --> 00:11:21,090
In fact, if I come at this one out, just so you can see.

140
00:11:25,040 --> 00:11:30,920
It doesn't run at all because now Hungary is false, so it does not meet the conditional expression

141
00:11:30,920 --> 00:11:33,110
required to run this line of code.

142
00:11:33,360 --> 00:11:41,930
So that is it for our review of single line comments, multiline comments, type coersion.

143
00:11:42,820 --> 00:11:44,110
And variable mutation.

144
00:11:46,180 --> 00:11:50,380
And we'll see you in the next video, we're going to talk a lot more about what variables are the different

145
00:11:50,380 --> 00:11:54,070
versions of variables and how we can make those work.
