WEBVTT

1
00:00:00.120 --> 00:00:03.000
<v Speaker 1>Welcome back to the deep dive. Ever looked at a

2
00:00:03.000 --> 00:00:06.160
<v Speaker 1>website and wondered, like, how did they do that?

3
00:00:06.400 --> 00:00:07.960
<v Speaker 2>It's the magic of JavaScript.

4
00:00:08.439 --> 00:00:11.359
<v Speaker 1>Well, today we're diving deep into that world, the world

5
00:00:11.439 --> 00:00:14.919
<v Speaker 1>of JavaScript. It's the language that you know, brings websites

6
00:00:14.960 --> 00:00:19.320
<v Speaker 1>to life, makes them interactive, engaging. We'll be using Kyle

7
00:00:19.359 --> 00:00:22.039
<v Speaker 1>Simpson's You Don't Know js Up and Going as our guide.

8
00:00:22.120 --> 00:00:24.120
<v Speaker 2>So fantastic resource it is.

9
00:00:24.199 --> 00:00:27.079
<v Speaker 1>Yeah. So, if you've ever been curious about, like, you know,

10
00:00:27.120 --> 00:00:30.199
<v Speaker 1>how those interactive maps work, or those cool animations or

11
00:00:30.239 --> 00:00:33.079
<v Speaker 1>even those forms that pop up, get ready for some

12
00:00:33.159 --> 00:00:34.560
<v Speaker 1>serious aha moments.

13
00:00:34.679 --> 00:00:38.520
<v Speaker 2>Yeah. JavaScript can seem intimidating at first, all that code, right,

14
00:00:38.679 --> 00:00:41.520
<v Speaker 2>but at its core, it's really just about giving instructions

15
00:00:41.520 --> 00:00:42.200
<v Speaker 2>to computers.

16
00:00:42.280 --> 00:00:46.200
<v Speaker 1>Okay, So like, are we basically like dog trainers for computers?

17
00:00:46.320 --> 00:00:48.560
<v Speaker 2>Kind of? Yeah? Yeah, you break down a trick into steps,

18
00:00:49.119 --> 00:00:52.159
<v Speaker 2>use clear signals, the dog understands, right, same with code.

19
00:00:52.320 --> 00:00:54.799
<v Speaker 2>We write instructions in a language the computer gets ah.

20
00:00:54.799 --> 00:00:57.320
<v Speaker 1>Okay, but computers don't speak English, do they.

21
00:00:57.439 --> 00:01:00.560
<v Speaker 2>Nope, they speak binary code, all zeros in one ones.

22
00:01:00.600 --> 00:01:03.240
<v Speaker 2>That's it pretty much. Thankfully we don't have to write

23
00:01:03.280 --> 00:01:03.479
<v Speaker 2>in that.

24
00:01:03.600 --> 00:01:07.359
<v Speaker 1>Yeah, I was gonna say. Programming languages like JavaScript, they

25
00:01:07.359 --> 00:01:12.159
<v Speaker 1>act as translators. We write human readable code, and JavaScript

26
00:01:12.200 --> 00:01:15.120
<v Speaker 1>converts that into the zeros and ones the computer needs.

27
00:01:15.239 --> 00:01:18.840
<v Speaker 2>So JavaScript is like the Rosetta Stone of the digital world.

28
00:01:18.959 --> 00:01:22.480
<v Speaker 2>I like that analogy. We write the instructions, JavaScript translates

29
00:01:22.519 --> 00:01:26.120
<v Speaker 2>them for the computer. Awesome. Okay, but what do these

30
00:01:26.239 --> 00:01:28.640
<v Speaker 2>instructions the code actually look like?

31
00:01:28.920 --> 00:01:32.200
<v Speaker 1>Good question. The instructions are made up of statements, which

32
00:01:32.200 --> 00:01:34.159
<v Speaker 1>are basically individual commands.

33
00:01:34.400 --> 00:01:34.680
<v Speaker 2>Okay.

34
00:01:34.799 --> 00:01:37.359
<v Speaker 1>Like, for example, a simple statement in JavaScript could be

35
00:01:37.439 --> 00:01:38.560
<v Speaker 1>A equals B two.

36
00:01:38.719 --> 00:01:42.799
<v Speaker 2>Okay, we're seeing letters, a number, some symbols. What's going on.

37
00:01:42.760 --> 00:01:45.079
<v Speaker 1>Here, right? So those letters A and B those are

38
00:01:45.079 --> 00:01:45.760
<v Speaker 1>called variables.

39
00:01:45.879 --> 00:01:46.319
<v Speaker 2>Variables.

40
00:01:46.480 --> 00:01:48.480
<v Speaker 1>I think of them like containers, each with a label

41
00:01:48.719 --> 00:01:51.280
<v Speaker 1>for storing information. Got it, And in this case they're

42
00:01:51.280 --> 00:01:54.959
<v Speaker 1>holding numbers. The two is a value that's written directly

43
00:01:55.000 --> 00:01:58.120
<v Speaker 1>into the code, and those symbols those are operators. Like

44
00:01:58.480 --> 00:02:01.200
<v Speaker 1>means multiply and it means a sign of value.

45
00:02:01.439 --> 00:02:04.719
<v Speaker 2>Okay, So this statement saying take the value in container B,

46
00:02:05.280 --> 00:02:08.039
<v Speaker 2>multiply it by two, and then stick the result into

47
00:02:08.039 --> 00:02:10.240
<v Speaker 2>container A. Exactly a recipe.

48
00:02:10.479 --> 00:02:13.159
<v Speaker 1>Yeah, kind of tick B. That a little spice you

49
00:02:13.199 --> 00:02:15.439
<v Speaker 1>know with multiplication and voila, you get Uh.

50
00:02:15.719 --> 00:02:18.439
<v Speaker 2>I like it, But why is this important? What can

51
00:02:18.439 --> 00:02:21.159
<v Speaker 2>we actually deal with these statements?

52
00:02:21.840 --> 00:02:25.000
<v Speaker 1>Well, by stringing these statements together, you can create programs

53
00:02:25.039 --> 00:02:28.759
<v Speaker 1>that can do pretty complex stuff like calculating the total

54
00:02:28.800 --> 00:02:31.560
<v Speaker 1>cost of items in a shopping cart or animating a

55
00:02:31.639 --> 00:02:32.520
<v Speaker 1>character on a screen.

56
00:02:33.000 --> 00:02:36.000
<v Speaker 2>So it's like building a house with lego bricks.

57
00:02:36.199 --> 00:02:38.639
<v Speaker 1>Yeah, each statement's a brick, and by combining them in

58
00:02:38.680 --> 00:02:40.800
<v Speaker 1>different ways we build all sorts of amazing things.

59
00:02:40.879 --> 00:02:44.680
<v Speaker 2>I love that. Now, within these statements you mentioned expressions,

60
00:02:45.039 --> 00:02:46.400
<v Speaker 2>What are those exactly?

61
00:02:46.960 --> 00:02:51.240
<v Speaker 1>Expressions are like the ingredients and many instructions within a statement. Okay,

62
00:02:51.360 --> 00:02:54.439
<v Speaker 1>in our example B two, that's an expression. It calculates

63
00:02:54.439 --> 00:02:57.840
<v Speaker 1>a value. Even just B on its own, that's an expression.

64
00:02:57.840 --> 00:02:59.560
<v Speaker 1>It refers to whatever is in that container.

65
00:03:00.039 --> 00:03:03.319
<v Speaker 2>Expressions are like the nuts and bolts of a statement.

66
00:03:03.400 --> 00:03:05.680
<v Speaker 1>You got it. And sometimes an expression can be a

67
00:03:05.680 --> 00:03:07.240
<v Speaker 1>whole statement by itself.

68
00:03:07.159 --> 00:03:10.560
<v Speaker 2>Like alerty, this would pop up a window on your

69
00:03:10.560 --> 00:03:13.520
<v Speaker 2>screen showing you the value stored in a It's both

70
00:03:13.560 --> 00:03:17.280
<v Speaker 2>an expression because it references a and a statement because

71
00:03:17.280 --> 00:03:18.479
<v Speaker 2>it causes that pop up.

72
00:03:18.960 --> 00:03:22.360
<v Speaker 1>Cool. So we've got programs made of statements. Statements built

73
00:03:22.400 --> 00:03:26.199
<v Speaker 1>with expressions. But how does this code actually r N.

74
00:03:26.719 --> 00:03:29.840
<v Speaker 1>It's not like the computer just magically understands what we've written,

75
00:03:29.960 --> 00:03:30.639
<v Speaker 1>right right.

76
00:03:30.759 --> 00:03:33.520
<v Speaker 2>That's where interpreters and compilers come in. Think of them

77
00:03:33.520 --> 00:03:36.439
<v Speaker 2>as language translators. They take our human readable code and

78
00:03:36.479 --> 00:03:41.039
<v Speaker 2>turn it into instructions the computer's processor can actually understand, so.

79
00:03:41.120 --> 00:03:44.199
<v Speaker 1>Like a chef translating the recipe into a language the

80
00:03:44.280 --> 00:03:46.280
<v Speaker 1>kitchen appliance can get exactly.

81
00:03:46.599 --> 00:03:50.319
<v Speaker 2>Some languages are interpreted line by line as the program runs, okay,

82
00:03:50.560 --> 00:03:53.879
<v Speaker 2>others are compiled all at once ahead of time. JavaScript's

83
00:03:53.879 --> 00:03:55.599
<v Speaker 2>a bit unique that it does something called just in

84
00:03:55.639 --> 00:03:58.879
<v Speaker 2>time compilation compiles the code right before running.

85
00:03:58.879 --> 00:04:00.000
<v Speaker 1>It a very efficient show.

86
00:04:00.319 --> 00:04:01.319
<v Speaker 2>Yeah you should say that.

87
00:04:01.400 --> 00:04:04.120
<v Speaker 1>So sounds like JavaScript is a very adaptable language.

88
00:04:04.159 --> 00:04:05.080
<v Speaker 2>It is very much so.

89
00:04:05.319 --> 00:04:08.159
<v Speaker 1>Okay, So we've got the basic building blocks, but we

90
00:04:08.240 --> 00:04:13.439
<v Speaker 1>deal with all sorts of data in the real world. Numbers, text, yes, no, decisions.

91
00:04:14.280 --> 00:04:16.439
<v Speaker 1>How does JavaScript handle all that?

92
00:04:16.439 --> 00:04:19.079
<v Speaker 2>That's where values and types come in, Just like in

93
00:04:19.120 --> 00:04:22.240
<v Speaker 2>a store. Right, you have different ways of representing values, okay,

94
00:04:22.439 --> 00:04:25.680
<v Speaker 2>like numbers for prices, words for descriptions, and yes or

95
00:04:25.720 --> 00:04:30.360
<v Speaker 2>no for availability. JavaScript uses different types to represent various

96
00:04:30.439 --> 00:04:31.839
<v Speaker 2>kinds of information.

97
00:04:31.480 --> 00:04:34.480
<v Speaker 1>So it's like having the right tool for the job exactly.

98
00:04:34.600 --> 00:04:40.040
<v Speaker 2>Javascripts built in types number for numerical data, string for text,

99
00:04:40.319 --> 00:04:42.519
<v Speaker 2>and boolean for tru or false values.

100
00:04:42.560 --> 00:04:44.360
<v Speaker 1>Okay, so if I want to store someone's age, i'd

101
00:04:44.439 --> 00:04:48.120
<v Speaker 1>use a number for their name, a string, and to

102
00:04:48.279 --> 00:04:50.720
<v Speaker 1>track if they're subscribed to something, a boolean.

103
00:04:51.079 --> 00:04:53.839
<v Speaker 2>Got it perfect, And you can write these values directly

104
00:04:53.879 --> 00:04:56.160
<v Speaker 2>into the code, like the number forty two or this

105
00:04:56.240 --> 00:04:59.639
<v Speaker 2>string Hello world. These are called literals because they represent

106
00:04:59.639 --> 00:05:00.439
<v Speaker 2>the value directly.

107
00:05:00.519 --> 00:05:02.600
<v Speaker 1>Makes sense. But what if I need to use a number,

108
00:05:02.920 --> 00:05:05.439
<v Speaker 1>say someone's age, within a sentence, do I have to

109
00:05:05.480 --> 00:05:06.759
<v Speaker 1>create a separate string for it?

110
00:05:06.839 --> 00:05:10.519
<v Speaker 2>Great question. JavaScript lets you convert between types. It's called coercion.

111
00:05:10.800 --> 00:05:14.319
<v Speaker 2>Coercion okay, like a magic wand transforming a number into

112
00:05:14.319 --> 00:05:17.399
<v Speaker 2>text and vice versa. So to combine a number and

113
00:05:17.439 --> 00:05:20.800
<v Speaker 2>a string, JavaScript can automatically convert the number into its.

114
00:05:20.759 --> 00:05:23.839
<v Speaker 1>String form handy. But are there any downsides to this

115
00:05:23.920 --> 00:05:24.560
<v Speaker 1>magic wand?

116
00:05:25.160 --> 00:05:29.319
<v Speaker 2>Well, there are actually two types of coercion, explicit and implicit.

117
00:05:29.959 --> 00:05:31.600
<v Speaker 1>Okay, I'm intrigued, tell me more.

118
00:05:32.079 --> 00:05:35.879
<v Speaker 2>Explicit coercion is when you intentionally tell JavaScript to convert

119
00:05:35.879 --> 00:05:40.000
<v Speaker 2>a value. It's like specifically telling the chef to chop

120
00:05:40.000 --> 00:05:42.959
<v Speaker 2>an onion into smaller pieces. For example, you can use

121
00:05:43.079 --> 00:05:45.079
<v Speaker 2>number to turn a scring into a number.

122
00:05:45.199 --> 00:05:48.079
<v Speaker 1>Okay, so that's deliberate. What about implicit.

123
00:05:47.639 --> 00:05:51.680
<v Speaker 2>Coercion, ah, Implicit coercion happens behind the scenes. It's when

124
00:05:51.759 --> 00:05:55.000
<v Speaker 2>JavaScript tries to make sense of operations involving different types.

125
00:05:55.199 --> 00:05:57.439
<v Speaker 2>It's like letting the chef decide how to prepare the

126
00:05:57.560 --> 00:06:01.240
<v Speaker 2>ingredients based on the recipe. But sometime the chef's interpretation

127
00:06:01.399 --> 00:06:02.920
<v Speaker 2>might differ from what you intended.

128
00:06:03.120 --> 00:06:06.519
<v Speaker 1>Ah. So implicit coercion can lead to surprises if you're

129
00:06:06.560 --> 00:06:07.839
<v Speaker 1>not careful exactly.

130
00:06:08.519 --> 00:06:10.519
<v Speaker 2>That's why it's important to be mindful of how you

131
00:06:10.639 --> 00:06:13.279
<v Speaker 2>use different types together. Like if you try to add

132
00:06:13.319 --> 00:06:17.399
<v Speaker 2>a number in a string, JavaScript might automatically convert the

133
00:06:17.399 --> 00:06:19.879
<v Speaker 2>string to a number, but the result might not be

134
00:06:19.920 --> 00:06:20.720
<v Speaker 2>what you expected.

135
00:06:21.160 --> 00:06:25.319
<v Speaker 1>So implicit coercion is powerful but requires a good understanding

136
00:06:25.399 --> 00:06:26.040
<v Speaker 1>of the rules.

137
00:06:26.199 --> 00:06:31.040
<v Speaker 2>Precisely mastering coercion is key to becoming a proficient JavaScript developer.

138
00:06:32.000 --> 00:06:34.879
<v Speaker 2>But we'll dig deeper into coercion in a later deep dive.

139
00:06:35.040 --> 00:06:38.360
<v Speaker 1>Looking forward to that, you briefly mentioned truthy and falsey

140
00:06:38.480 --> 00:06:40.879
<v Speaker 1>values before can you explain that a bit more sure?

141
00:06:41.040 --> 00:06:43.360
<v Speaker 2>So, sometimes you need to check if a value is

142
00:06:43.439 --> 00:06:47.199
<v Speaker 2>truth or falsey. Basically, would it be considered true or

143
00:06:47.199 --> 00:06:48.639
<v Speaker 2>false in a conditional statement?

144
00:06:48.839 --> 00:06:49.199
<v Speaker 1>Okay?

145
00:06:49.399 --> 00:06:52.639
<v Speaker 2>In JavaScript, certain values are always considered falsey, Like an

146
00:06:52.639 --> 00:06:56.279
<v Speaker 2>empty string, the number zero, or the values null and undefined.

147
00:06:56.319 --> 00:06:58.279
<v Speaker 1>So those are always missing in our recipe.

148
00:06:58.279 --> 00:07:01.399
<v Speaker 2>Great analogy, and anything that's not on that falsey list

149
00:07:01.439 --> 00:07:02.360
<v Speaker 2>that's considered truthy.

150
00:07:02.439 --> 00:07:05.160
<v Speaker 1>Okay, So a non empty string, a non zero number,

151
00:07:05.319 --> 00:07:08.360
<v Speaker 1>a true boolean, those would all be truthy.

152
00:07:08.600 --> 00:07:11.759
<v Speaker 2>You, got it, and JavaScript can automatically coerce those to

153
00:07:11.879 --> 00:07:14.639
<v Speaker 2>true or false when needed in conditions or comparisons.

154
00:07:14.720 --> 00:07:16.920
<v Speaker 1>Got it. It's like having a built in sensor that

155
00:07:16.959 --> 00:07:19.199
<v Speaker 1>can tell if an ingredient is present or missing in

156
00:07:19.240 --> 00:07:19.759
<v Speaker 1>our recipe.

157
00:07:19.839 --> 00:07:20.279
<v Speaker 2>I like that.

158
00:07:20.480 --> 00:07:23.800
<v Speaker 1>Now let's talk about comparing values. How does JavaScript know

159
00:07:23.839 --> 00:07:25.000
<v Speaker 1>if two values are equal?

160
00:07:25.399 --> 00:07:29.040
<v Speaker 2>JavaScript provides operators for comparing values. Yeah. The most common

161
00:07:29.079 --> 00:07:31.360
<v Speaker 2>ones are double equals and triple equals.

162
00:07:31.399 --> 00:07:34.319
<v Speaker 1>I've heard double equals is evil and should be avoided.

163
00:07:34.399 --> 00:07:34.920
<v Speaker 1>Is that true?

164
00:07:35.240 --> 00:07:38.519
<v Speaker 2>Not necessarily, It's about using the right tool for the job.

165
00:07:38.759 --> 00:07:39.120
<v Speaker 1>Okay.

166
00:07:39.240 --> 00:07:43.480
<v Speaker 2>Double equals allows for coercion, meaning it can compare values

167
00:07:43.519 --> 00:07:47.560
<v Speaker 2>of different types. Triple equals is strict. It only considers

168
00:07:47.639 --> 00:07:50.439
<v Speaker 2>values equal if they're both the same value A D

169
00:07:50.639 --> 00:07:51.360
<v Speaker 2>the same type.

170
00:07:51.519 --> 00:07:54.120
<v Speaker 1>So it's like having two different scales, one that can

171
00:07:54.399 --> 00:07:56.959
<v Speaker 1>weigh different kinds of objects, maybe by converting them to

172
00:07:57.000 --> 00:08:00.279
<v Speaker 1>a common unit, and another that requires objects to be

173
00:08:00.360 --> 00:08:02.800
<v Speaker 1>of the same type for a precise measurement.

174
00:08:03.079 --> 00:08:05.480
<v Speaker 2>I like that analogy. So if you're unsure about the

175
00:08:05.480 --> 00:08:09.160
<v Speaker 2>types you're comparing, it's safer to use triple equals avoid

176
00:08:09.240 --> 00:08:12.879
<v Speaker 2>surprises from coercion. But if you're confident and want to

177
00:08:12.959 --> 00:08:16.360
<v Speaker 2>leverage coercion, double equals can be handy. The key is

178
00:08:16.439 --> 00:08:18.360
<v Speaker 2>understanding its strengths and limitations.

179
00:08:18.600 --> 00:08:22.079
<v Speaker 1>Got it. It's about choosing the right tool, not fearing

180
00:08:22.160 --> 00:08:25.800
<v Speaker 1>one or the other. Okay, so we've got values, types,

181
00:08:25.839 --> 00:08:27.839
<v Speaker 1>coercion comparisons. What's next.

182
00:08:28.240 --> 00:08:31.480
<v Speaker 2>Let's talk about variables from those containers we were talking about. Yeah,

183
00:08:31.519 --> 00:08:34.759
<v Speaker 2>to declare a variable, we use the var keyword. Okay,

184
00:08:35.039 --> 00:08:37.240
<v Speaker 2>And a variable's name has to follow some rules. It

185
00:08:37.240 --> 00:08:39.480
<v Speaker 2>has to start with a letter, a dollar sign, or

186
00:08:39.480 --> 00:08:42.279
<v Speaker 2>an underscore, got it. And then it can contain letters, numbers,

187
00:08:42.320 --> 00:08:43.720
<v Speaker 2>dollar signs, or underscores.

188
00:08:44.080 --> 00:08:47.799
<v Speaker 1>So something like my variable or amount would be valid

189
00:08:47.879 --> 00:08:49.399
<v Speaker 1>variable names exactly.

190
00:08:49.720 --> 00:08:52.799
<v Speaker 2>It's super important to choose descriptive names that clearly show

191
00:08:52.799 --> 00:08:53.519
<v Speaker 2>what they hold.

192
00:08:53.399 --> 00:08:55.679
<v Speaker 1>Right like bank balance is much clearer than just B

193
00:08:56.080 --> 00:08:58.120
<v Speaker 1>makes the code so much easier to understand.

194
00:08:58.200 --> 00:09:02.360
<v Speaker 2>Absolutely clear variable names are essential for readability. Imagine trying

195
00:09:02.360 --> 00:09:05.279
<v Speaker 2>to decipher a recipe where all the ingredients were labeled

196
00:09:05.320 --> 00:09:06.799
<v Speaker 2>ABC and so on.

197
00:09:07.080 --> 00:09:09.799
<v Speaker 1>Oh, that would be a nightmare. Now, how about where

198
00:09:09.840 --> 00:09:12.759
<v Speaker 1>you can use these variables? Like, if a variable is

199
00:09:12.799 --> 00:09:17.120
<v Speaker 1>declared inside a function, is it only available within that function?

200
00:09:17.679 --> 00:09:20.440
<v Speaker 2>That's a great question that brings us to scope scope book.

201
00:09:20.720 --> 00:09:24.240
<v Speaker 2>In JavaScript, functions create their own scopes, kind of like

202
00:09:24.320 --> 00:09:28.360
<v Speaker 2>walled gardens where variables live. Okay, a variable declared inside

203
00:09:28.399 --> 00:09:32.080
<v Speaker 2>a function is only accessible within that function scope, not outside.

204
00:09:32.159 --> 00:09:34.759
<v Speaker 1>So it's like having separate rooms in a house, each

205
00:09:34.799 --> 00:09:37.200
<v Speaker 1>with its own set of belongings that aren't visible from

206
00:09:37.200 --> 00:09:37.799
<v Speaker 1>other rooms.

207
00:09:37.919 --> 00:09:41.360
<v Speaker 2>Perfect analogy, And just like rooms within a house, you

208
00:09:41.399 --> 00:09:45.559
<v Speaker 2>can have nested scopes in JavaScript. A function inside another

209
00:09:45.639 --> 00:09:48.840
<v Speaker 2>function has access to variables from the outer function scope,

210
00:09:49.240 --> 00:09:52.000
<v Speaker 2>but the outer function can't peak into the inner functions

211
00:09:52.039 --> 00:09:52.720
<v Speaker 2>private space.

212
00:09:52.879 --> 00:09:55.120
<v Speaker 1>So if I have a function called calculate total inside

213
00:09:55.159 --> 00:09:58.519
<v Speaker 1>a function called process, order calculate total can access variables

214
00:09:58.519 --> 00:10:00.799
<v Speaker 1>from process order, but not the the other way around.

215
00:10:01.000 --> 00:10:06.960
<v Speaker 2>Exactly. Understanding scope is crucial for writing well organized JavaScript code. Now,

216
00:10:07.000 --> 00:10:09.879
<v Speaker 2>there's this quirky thing called hoisting, which can trip up

217
00:10:09.960 --> 00:10:11.440
<v Speaker 2>even experience developers.

218
00:10:11.720 --> 00:10:14.639
<v Speaker 1>Hoisting sounds a bit ominous.

219
00:10:15.200 --> 00:10:18.639
<v Speaker 2>Imagine a magical crane that lifts all the variable declarations

220
00:10:18.679 --> 00:10:20.519
<v Speaker 2>to the top of a room, even if you wrote

221
00:10:20.559 --> 00:10:23.360
<v Speaker 2>them lower down. Okay, that's kind of what hoisting does.

222
00:10:23.360 --> 00:10:27.440
<v Speaker 2>In JavaScript. Variable and function declarations are conceptually moved to

223
00:10:27.480 --> 00:10:29.159
<v Speaker 2>the top of their scope during compilation.

224
00:10:30.000 --> 00:10:33.480
<v Speaker 1>So I could technically use a variable before declaring.

225
00:10:33.000 --> 00:10:36.320
<v Speaker 2>It, you could. Yeah, hoisting can lead to confusion, especially

226
00:10:36.399 --> 00:10:39.840
<v Speaker 2>in large projects. While you can technically use a variable

227
00:10:39.879 --> 00:10:43.279
<v Speaker 2>before its declaration, it's way better to declare your variables

228
00:10:43.279 --> 00:10:44.320
<v Speaker 2>at the top for clarity.

229
00:10:44.919 --> 00:10:47.799
<v Speaker 1>Okay, so hoisting is one of those JavaScript quirks that's

230
00:10:47.879 --> 00:10:51.279
<v Speaker 1>good to be aware of, but maybe not rely on exactly. Now,

231
00:10:51.320 --> 00:10:54.279
<v Speaker 1>besides this function level scope, are there any other kinds

232
00:10:54.279 --> 00:10:55.399
<v Speaker 1>of scope in JavaScript?

233
00:10:55.879 --> 00:10:58.799
<v Speaker 2>Yes? With ES six, we got a new way to

234
00:10:58.799 --> 00:11:00.840
<v Speaker 2>declare variables using let keyword.

235
00:11:01.080 --> 00:11:01.440
<v Speaker 1>Okay.

236
00:11:01.639 --> 00:11:05.600
<v Speaker 2>This lets you create block level scopes, meaning variables declared

237
00:11:05.679 --> 00:11:08.279
<v Speaker 2>inside a block of code, like an if statement or

238
00:11:08.279 --> 00:11:10.960
<v Speaker 2>a loop are only accessible within that block.

239
00:11:11.240 --> 00:11:13.919
<v Speaker 1>Ah. So it's like having smaller compartments within a room

240
00:11:13.919 --> 00:11:15.159
<v Speaker 1>to organize your belongings.

241
00:11:15.159 --> 00:11:19.320
<v Speaker 2>Even further precisely, block level scoping gives you finer control

242
00:11:19.480 --> 00:11:20.799
<v Speaker 2>over variable visibility.

243
00:11:21.120 --> 00:11:24.720
<v Speaker 1>This is great. So we've got scope hoisting and block

244
00:11:24.799 --> 00:11:28.000
<v Speaker 1>level scoping. What's next on our JavaScript adventure?

245
00:11:28.120 --> 00:11:31.600
<v Speaker 2>Let's revisit conditional statements. It's where we make decisions in

246
00:11:31.639 --> 00:11:34.799
<v Speaker 2>our code based on certain conditions. We've touched on the

247
00:11:34.840 --> 00:11:38.279
<v Speaker 2>if statement, but JavaScript also has the switch statement for

248
00:11:38.360 --> 00:11:39.720
<v Speaker 2>handling multiple conditions.

249
00:11:39.840 --> 00:11:41.840
<v Speaker 1>Okay, remind me what does the if statement do again?

250
00:11:41.960 --> 00:11:44.919
<v Speaker 2>The if statement executes a block of code only if

251
00:11:44.960 --> 00:11:48.279
<v Speaker 2>a condition is true, like a gatekeeper who only allows

252
00:11:48.399 --> 00:11:50.120
<v Speaker 2>entry if a certain condition is met.

253
00:11:50.240 --> 00:11:52.600
<v Speaker 1>Got it? So if I want to check if a

254
00:11:52.679 --> 00:11:55.080
<v Speaker 1>user is logged in before sharing their profile, I'd use

255
00:11:55.120 --> 00:11:57.120
<v Speaker 1>an if statement. What about the switch statement? When wou

256
00:11:57.159 --> 00:11:57.559
<v Speaker 1>I use that?

257
00:11:57.799 --> 00:12:00.559
<v Speaker 2>The switch statement is like a multi way switch. It

258
00:12:00.639 --> 00:12:03.320
<v Speaker 2>directs the flow of execution to different blocks of code

259
00:12:03.639 --> 00:12:06.879
<v Speaker 2>based on the value of a variable or expression. It's

260
00:12:06.919 --> 00:12:09.679
<v Speaker 2>more concise than a chain of if and l's if statements,

261
00:12:09.879 --> 00:12:12.000
<v Speaker 2>especially when you have many conditions to check.

262
00:12:12.159 --> 00:12:14.039
<v Speaker 1>So instead of having a series of if and l's

263
00:12:14.080 --> 00:12:16.840
<v Speaker 1>if statements, I can use a switch statement to neatly

264
00:12:16.960 --> 00:12:19.440
<v Speaker 1>organize multiple conditions exactly.

265
00:12:19.519 --> 00:12:21.360
<v Speaker 2>It can make your code much easier to read.

266
00:12:21.720 --> 00:12:25.399
<v Speaker 1>Makes sense, But there's a catch right You mentioned that

267
00:12:25.440 --> 00:12:28.519
<v Speaker 1>sometimes code can fall through from one case to the

268
00:12:28.559 --> 00:12:29.799
<v Speaker 1>next in a switch statement.

269
00:12:30.039 --> 00:12:32.960
<v Speaker 2>Ah. Yes, fall through. Think of it like a secret

270
00:12:32.960 --> 00:12:36.559
<v Speaker 2>passage that connects different rooms in a house. Normally, you'd

271
00:12:36.600 --> 00:12:39.320
<v Speaker 2>want each case to be separate, so you use the

272
00:12:39.360 --> 00:12:43.440
<v Speaker 2>break keyword to stop execution after a matching case. But

273
00:12:43.559 --> 00:12:47.320
<v Speaker 2>sometimes you might intentionally want to execute multiple cases in

274
00:12:47.360 --> 00:12:50.240
<v Speaker 2>a row, and that's where fall through comes in handy.

275
00:12:50.360 --> 00:12:53.000
<v Speaker 1>So it's like having a shortcut that lets you access

276
00:12:53.159 --> 00:12:56.000
<v Speaker 1>multiple rooms with a single key. Can you give me

277
00:12:56.039 --> 00:12:58.480
<v Speaker 1>an example of when this fall through would be useful?

278
00:12:58.559 --> 00:13:03.279
<v Speaker 2>Sure? Imagine building a game and different actions have the

279
00:13:03.279 --> 00:13:06.039
<v Speaker 2>same outcome. You could use a switch statement with fall

280
00:13:06.080 --> 00:13:09.120
<v Speaker 2>through to handle those actions together instead of repeating the

281
00:13:09.159 --> 00:13:10.759
<v Speaker 2>same logic in multiple cases.

282
00:13:10.840 --> 00:13:13.279
<v Speaker 1>Ah, that makes sense. So we've got if and switch

283
00:13:13.360 --> 00:13:16.080
<v Speaker 1>for handling conditions. Are there any other ways to express

284
00:13:16.080 --> 00:13:17.320
<v Speaker 1>conditions in JavaScript?

285
00:13:17.399 --> 00:13:22.799
<v Speaker 2>Yep? There's also the conditional operator, sometimes called the ternary operator.

286
00:13:22.879 --> 00:13:25.720
<v Speaker 2>It's like a compact version of the if L statement. Okay.

287
00:13:25.799 --> 00:13:29.360
<v Speaker 2>It uses a question mark and a colon to represent

288
00:13:29.440 --> 00:13:30.799
<v Speaker 2>the two possible outcomes.

289
00:13:30.919 --> 00:13:32.000
<v Speaker 1>Can you show me an example.

290
00:13:32.039 --> 00:13:34.559
<v Speaker 2>Sure. Let's say you want to display a different message

291
00:13:34.600 --> 00:13:37.279
<v Speaker 2>based on whether a user is logged in. You could

292
00:13:37.320 --> 00:13:40.240
<v Speaker 2>use the conditional operator like this lem a message is

293
00:13:40.279 --> 00:13:42.519
<v Speaker 2>logged in, welcome back, please log in.

294
00:13:42.919 --> 00:13:44.840
<v Speaker 1>Okay. So it's a shorthand way of doing that. Pretty

295
00:13:44.879 --> 00:13:48.639
<v Speaker 1>neat right now. You also mentioned something about strict mode

296
00:13:48.799 --> 00:13:50.759
<v Speaker 1>in JavaScript. What's that all about?

297
00:13:51.039 --> 00:13:53.960
<v Speaker 2>Strict mode? It was introduced in e S five. Think

298
00:13:53.960 --> 00:13:57.279
<v Speaker 2>of it as having a much stricter building inspector checking

299
00:13:57.320 --> 00:13:59.000
<v Speaker 2>your code for potential hazards.

300
00:13:59.039 --> 00:14:01.799
<v Speaker 1>Okay, I like that. Tell me more about these hazards.

301
00:14:01.840 --> 00:14:07.200
<v Speaker 2>One example is accidental global variable creation in regular JavaScript.

302
00:14:07.440 --> 00:14:10.759
<v Speaker 2>If you forget to declare a variable using var, it

303
00:14:10.840 --> 00:14:14.120
<v Speaker 2>might accidentally become a global variable accessible from anywhere in

304
00:14:14.159 --> 00:14:14.600
<v Speaker 2>your code.

305
00:14:14.759 --> 00:14:16.360
<v Speaker 1>Oh, that sounds dangerous.

306
00:14:16.600 --> 00:14:20.240
<v Speaker 2>It can be leads to unexpected behavior, hard to find bugs.

307
00:14:20.840 --> 00:14:24.559
<v Speaker 2>Strict mode prevents this by throwing an error if you

308
00:14:24.679 --> 00:14:27.039
<v Speaker 2>try to assign a value to an undeclared variable.

309
00:14:27.080 --> 00:14:28.840
<v Speaker 1>So it's like a safety net exactly.

310
00:14:29.039 --> 00:14:32.399
<v Speaker 2>You enable strict mode. By adding you strict at the

311
00:14:32.440 --> 00:14:33.799
<v Speaker 2>top of a function or a file.

312
00:14:34.039 --> 00:14:35.799
<v Speaker 1>Got it? Are there any other benefits?

313
00:14:36.480 --> 00:14:39.759
<v Speaker 2>Yes? It also makes your code more optimizable, could lead

314
00:14:39.759 --> 00:14:44.000
<v Speaker 2>to better performance, and it encourages best practices, helps you

315
00:14:44.039 --> 00:14:46.960
<v Speaker 2>avoid bad habits that might not be supported in future

316
00:14:47.000 --> 00:14:48.000
<v Speaker 2>JavaScript versions.

317
00:14:48.240 --> 00:14:50.919
<v Speaker 1>So it's like building your house to meet the latest

318
00:14:50.919 --> 00:14:54.919
<v Speaker 1>safety and efficiency standards. Good investment. Okay, we've covered a

319
00:14:54.960 --> 00:14:56.519
<v Speaker 1>lot of ground here. What's next.

320
00:14:56.919 --> 00:14:59.000
<v Speaker 2>Now let's move on to one of the most powerful

321
00:14:59.120 --> 00:15:04.399
<v Speaker 2>and often mis understood concepts and genrefript functions as values.

322
00:15:04.600 --> 00:15:06.639
<v Speaker 1>Oooh, this is where things get interesting.

323
00:15:06.799 --> 00:15:09.120
<v Speaker 2>It is Remember how I said functions can be treated

324
00:15:09.200 --> 00:15:10.919
<v Speaker 2>like any other value in JavaScript.

325
00:15:11.000 --> 00:15:11.120
<v Speaker 1>Ye.

326
00:15:11.320 --> 00:15:14.720
<v Speaker 2>Think of functions like versatile tools, usable in many different ways.

327
00:15:15.159 --> 00:15:17.639
<v Speaker 2>You could assign a function to a variable, pass it

328
00:15:17.679 --> 00:15:20.360
<v Speaker 2>as an argument to another function, or even return a

329
00:15:20.399 --> 00:15:21.519
<v Speaker 2>function from another function.

330
00:15:21.720 --> 00:15:23.960
<v Speaker 1>Wow, that's pretty flexible. Can you give me an example

331
00:15:23.960 --> 00:15:24.960
<v Speaker 1>of why this is useful?

332
00:15:25.200 --> 00:15:27.960
<v Speaker 2>Sure? Imagine you're building a game and you need to

333
00:15:28.000 --> 00:15:31.240
<v Speaker 2>perform different actions based on user input. You could have

334
00:15:31.279 --> 00:15:34.519
<v Speaker 2>a function for each action like move left, move right, jump,

335
00:15:34.559 --> 00:15:37.879
<v Speaker 2>and so on. By treating these functions as values, you

336
00:15:37.879 --> 00:15:40.840
<v Speaker 2>can store them in an array and then easily call

337
00:15:40.879 --> 00:15:44.480
<v Speaker 2>the appropriate function based on the user's input without writing

338
00:15:44.559 --> 00:15:46.799
<v Speaker 2>a bunch of repetitive if statements.

339
00:15:47.200 --> 00:15:50.759
<v Speaker 1>Ah. So it's like having a toolbox with labeled compartments

340
00:15:50.759 --> 00:15:52.879
<v Speaker 1>for each tool. You can grab the right tool for

341
00:15:52.919 --> 00:15:55.200
<v Speaker 1>the job without having to rummage through a messy pile.

342
00:15:55.399 --> 00:15:55.960
<v Speaker 2>Exactly.

343
00:15:56.080 --> 00:15:58.600
<v Speaker 1>I like that. Now, how do we create a function

344
00:15:58.679 --> 00:15:59.919
<v Speaker 1>as of value?

345
00:16:00.120 --> 00:16:03.200
<v Speaker 2>Way is to use a function expression. It's like writing

346
00:16:03.240 --> 00:16:05.159
<v Speaker 2>down the steps of a recipe on a piece of

347
00:16:05.200 --> 00:16:08.480
<v Speaker 2>paper and then putting that paper into a labeled envelope.

348
00:16:08.679 --> 00:16:11.000
<v Speaker 2>For example, let my function function.

349
00:16:11.080 --> 00:16:13.159
<v Speaker 1>Okay, and then I can use that variable my function

350
00:16:13.240 --> 00:16:15.120
<v Speaker 1>to call the function, just like I would with a

351
00:16:15.200 --> 00:16:15.799
<v Speaker 1>named function.

352
00:16:15.960 --> 00:16:17.240
<v Speaker 2>Precisely cool.

353
00:16:17.679 --> 00:16:19.200
<v Speaker 1>Now, what if you have a function that you only

354
00:16:19.279 --> 00:16:20.039
<v Speaker 1>need to use once.

355
00:16:20.399 --> 00:16:25.159
<v Speaker 2>Ah, that's where immediately invote function expressions come in, or

356
00:16:25.320 --> 00:16:28.639
<v Speaker 2>iafes for short. Yeah, it's like writing a recipe and

357
00:16:28.679 --> 00:16:31.480
<v Speaker 2>then immediately starting to cook it without saving it for later.

358
00:16:31.600 --> 00:16:32.360
<v Speaker 1>Sounds efficient.

359
00:16:32.559 --> 00:16:36.120
<v Speaker 2>It is. You basically wrap the function expression in parentheses

360
00:16:36.360 --> 00:16:38.519
<v Speaker 2>and then add another set of parentheses at the end

361
00:16:38.720 --> 00:16:40.799
<v Speaker 2>to invoke it right away like this.

362
00:16:41.200 --> 00:16:44.080
<v Speaker 1>Okay, so those extra parentheses at the end trigger the

363
00:16:44.080 --> 00:16:47.039
<v Speaker 1>immediate execution. But why would we want to do this.

364
00:16:47.720 --> 00:16:51.159
<v Speaker 2>One common use is to create a private scope for

365
00:16:51.320 --> 00:16:55.000
<v Speaker 2>variables and functions, prevents them from cluttering up the global

366
00:16:55.039 --> 00:16:57.440
<v Speaker 2>scope and potentially clashing with other code.

367
00:16:57.600 --> 00:17:00.320
<v Speaker 1>Ah. So it's like having a separate workspace where you

368
00:17:00.320 --> 00:17:03.600
<v Speaker 1>can experiment without messing up your main project. You got it,

369
00:17:03.759 --> 00:17:06.720
<v Speaker 1>I like it. Now let's talk about closures. This is

370
00:17:06.720 --> 00:17:09.160
<v Speaker 1>one of those concepts I've always found a bit mysterious.

371
00:17:09.279 --> 00:17:14.200
<v Speaker 2>Closures are indeed powerful and often misunderstood. Imagine you have

372
00:17:14.240 --> 00:17:18.279
<v Speaker 2>a function that returns another function okay, The inner function

373
00:17:18.599 --> 00:17:21.880
<v Speaker 2>still has access to the outer function scope even after

374
00:17:21.920 --> 00:17:24.440
<v Speaker 2>the outer function is finished running. That's closure.

375
00:17:24.720 --> 00:17:27.000
<v Speaker 1>So it's like the inner function carries a little piece

376
00:17:27.039 --> 00:17:29.279
<v Speaker 1>of its birthplace with it wherever it goes.

377
00:17:29.519 --> 00:17:32.359
<v Speaker 2>That's a great way to put it. Closures are powerful

378
00:17:32.559 --> 00:17:35.640
<v Speaker 2>because they let you create functions that have access to

379
00:17:35.680 --> 00:17:40.200
<v Speaker 2>private data, leading to more modular and maintainable code. A

380
00:17:40.240 --> 00:17:42.720
<v Speaker 2>classic example is creating a counter function.

381
00:17:43.039 --> 00:17:46.160
<v Speaker 1>A counter function. How does that work with closures?

382
00:17:46.640 --> 00:17:49.400
<v Speaker 2>Imagine you have a function called may counter that returns

383
00:17:49.400 --> 00:17:52.799
<v Speaker 2>another function Okay. Inside make counter, you have a variable,

384
00:17:52.920 --> 00:17:56.839
<v Speaker 2>let's call it count, initialized to zero. The inner function,

385
00:17:56.960 --> 00:18:01.039
<v Speaker 2>when called increments count and returns its new value. Each

386
00:18:01.079 --> 00:18:03.240
<v Speaker 2>time you call make counter, it creates a new closure

387
00:18:03.400 --> 00:18:05.240
<v Speaker 2>with his own independent count variable.

388
00:18:05.319 --> 00:18:07.400
<v Speaker 1>So I could create two counters, each with their own

389
00:18:07.480 --> 00:18:10.759
<v Speaker 1>count even though they come from the same make counterfunction exactly.

390
00:18:10.920 --> 00:18:13.640
<v Speaker 2>That's the magic of closures. They let you create multiple

391
00:18:13.640 --> 00:18:17.200
<v Speaker 2>instances of a function, each with their own private data.

392
00:18:17.279 --> 00:18:19.720
<v Speaker 2>This concept is actually a building block for something called

393
00:18:19.720 --> 00:18:22.359
<v Speaker 2>the module pattern, which we'll explore more later.

394
00:18:22.720 --> 00:18:26.160
<v Speaker 1>This is fascinating. It seems like closures are essential for

395
00:18:26.200 --> 00:18:27.759
<v Speaker 1>a well structured JavaScript.

396
00:18:28.039 --> 00:18:29.400
<v Speaker 2>They are extremely useful.

397
00:18:29.480 --> 00:18:31.160
<v Speaker 1>Yes, but I have a feeling this is just the

398
00:18:31.200 --> 00:18:32.079
<v Speaker 1>tip of the iceberg.

399
00:18:32.279 --> 00:18:36.480
<v Speaker 2>Oh. Absolutely, closures open up a whole new dimension in JavaScript.

400
00:18:37.039 --> 00:18:40.240
<v Speaker 2>But for now, let's move on to another intriguing concept.

401
00:18:41.279 --> 00:18:42.039
<v Speaker 2>This keyword.

402
00:18:42.319 --> 00:18:45.759
<v Speaker 1>Ah, yes, the infamous this. I've heard a lot about it,

403
00:18:45.799 --> 00:18:48.440
<v Speaker 1>but it's always seemed a bit mysterious. What's the biggest

404
00:18:48.440 --> 00:18:49.680
<v Speaker 1>misconception about this?

405
00:18:50.319 --> 00:18:52.559
<v Speaker 2>The biggest one is that this always refers to the

406
00:18:52.599 --> 00:18:57.559
<v Speaker 2>function itself. But that's not true. This is dynamic, Like

407
00:18:57.599 --> 00:19:00.640
<v Speaker 2>a chameleon. It changes based on its surrounding. It can

408
00:19:00.680 --> 00:19:03.400
<v Speaker 2>refer to different objects depending on how the function is called.

409
00:19:03.480 --> 00:19:05.039
<v Speaker 1>Okay, so this is a bit of a shape shifter.

410
00:19:05.119 --> 00:19:06.799
<v Speaker 1>How do we know what it refers to at any

411
00:19:06.839 --> 00:19:07.400
<v Speaker 1>given time?

412
00:19:07.599 --> 00:19:10.079
<v Speaker 2>There are four main rules that determine what this refers to.

413
00:19:10.200 --> 00:19:11.000
<v Speaker 1>Okay, lameamy.

414
00:19:11.200 --> 00:19:14.680
<v Speaker 2>First rule is the default binding. When a function is

415
00:19:14.680 --> 00:19:18.079
<v Speaker 2>called normally, this usually refers to the global object. It's

416
00:19:18.119 --> 00:19:21.440
<v Speaker 2>like the default environment where JavaScript code runs.

417
00:19:21.200 --> 00:19:23.839
<v Speaker 1>So it's like the default setting on a device exactly.

418
00:19:24.200 --> 00:19:26.960
<v Speaker 2>Second rule is implicit binding. This comes into play what

419
00:19:27.000 --> 00:19:28.880
<v Speaker 2>a function is called as a method of an object.

420
00:19:29.559 --> 00:19:31.960
<v Speaker 2>This then refers to the object that owns the method.

421
00:19:32.240 --> 00:19:34.839
<v Speaker 1>Okay, so if I have an object called car with

422
00:19:34.920 --> 00:19:38.039
<v Speaker 1>a method called start, and I call car dot start,

423
00:19:38.519 --> 00:19:40.880
<v Speaker 1>then this inside the start method would refer to the

424
00:19:40.880 --> 00:19:41.759
<v Speaker 1>Car object.

425
00:19:41.960 --> 00:19:46.240
<v Speaker 2>You got it. Third rule is explicit binding. You intentionally

426
00:19:46.319 --> 00:19:50.200
<v Speaker 2>force this to refer to a specific object using methods

427
00:19:50.240 --> 00:19:51.519
<v Speaker 2>like call or apply.

428
00:19:51.480 --> 00:19:55.160
<v Speaker 1>So we can override the default this behavior in certain situations.

429
00:19:55.240 --> 00:19:58.039
<v Speaker 2>You got it. And the fourth rule is the new binding.

430
00:19:58.599 --> 00:20:01.160
<v Speaker 2>Use when you call a function with new keyword to

431
00:20:01.200 --> 00:20:04.000
<v Speaker 2>create a new object, this then refers to this newly

432
00:20:04.039 --> 00:20:04.799
<v Speaker 2>created object.

433
00:20:04.839 --> 00:20:08.920
<v Speaker 1>Okay, So we have these four rules default, implicit, explicit,

434
00:20:09.000 --> 00:20:12.279
<v Speaker 1>and new binding. Seems like understanding these is key to

435
00:20:12.319 --> 00:20:13.880
<v Speaker 1>mastering this absolutely.

436
00:20:14.319 --> 00:20:17.240
<v Speaker 2>Once you grasp these rules, this becomes much less mysterious.

437
00:20:17.480 --> 00:20:19.640
<v Speaker 2>But we'll dive deeper into each rule in a later

438
00:20:19.720 --> 00:20:20.759
<v Speaker 2>deep dive looking.

439
00:20:20.559 --> 00:20:22.640
<v Speaker 1>Forward to that. Now, before we wrap up this part

440
00:20:22.680 --> 00:20:26.200
<v Speaker 1>of our JavaScript adventure, let's touch on one more topic prototypes.

441
00:20:26.559 --> 00:20:29.960
<v Speaker 2>Prototypes they're fundamental to JavaScript. They provide a way for

442
00:20:30.000 --> 00:20:33.480
<v Speaker 2>objects to inherit properties and methods from other objects. Think

443
00:20:33.480 --> 00:20:35.759
<v Speaker 2>of it like a family tree where objects can inherit

444
00:20:35.799 --> 00:20:37.279
<v Speaker 2>traits from their ancestors.

445
00:20:37.279 --> 00:20:40.839
<v Speaker 1>Interesting, So does this help us write more efficient code?

446
00:20:41.000 --> 00:20:44.720
<v Speaker 2>Absolutely? Every object in JavaScript has an internal link to

447
00:20:44.759 --> 00:20:48.480
<v Speaker 2>another object called its prototype. Okay, When you try to

448
00:20:48.559 --> 00:20:51.920
<v Speaker 2>access a property on an object, JavaScript checks if that

449
00:20:52.000 --> 00:20:55.720
<v Speaker 2>property exists directly on the object. If not, it follows

450
00:20:55.720 --> 00:20:59.319
<v Speaker 2>the prototype chain looking for that property on the object's prototype,

451
00:20:59.319 --> 00:21:01.960
<v Speaker 2>and so on until it finds it or reaches the

452
00:21:02.039 --> 00:21:02.640
<v Speaker 2>end of the chain.

453
00:21:02.920 --> 00:21:05.400
<v Speaker 1>So it's like searching for a book in a library.

454
00:21:05.880 --> 00:21:07.599
<v Speaker 1>You first check the shelf where it's supposed to be.

455
00:21:07.599 --> 00:21:09.759
<v Speaker 1>If it's not there, you check the catalog to see

456
00:21:09.799 --> 00:21:12.799
<v Speaker 1>if it's in another section or maybe borrowed by another library.

457
00:21:12.920 --> 00:21:16.160
<v Speaker 2>That's a great analogy. This prototype chain allows objects to

458
00:21:16.160 --> 00:21:21.039
<v Speaker 2>share functionality without duplicating code. Leads to big performance improvements

459
00:21:21.039 --> 00:21:22.400
<v Speaker 2>and more organized code.

460
00:21:22.559 --> 00:21:25.319
<v Speaker 1>That's awesome, But I've also heard that prototypes are sometimes

461
00:21:25.400 --> 00:21:29.640
<v Speaker 1>used to emulate classes and inheritance, which can be problematic.

462
00:21:29.839 --> 00:21:31.200
<v Speaker 1>Can you elaborate on that.

463
00:21:31.400 --> 00:21:35.119
<v Speaker 2>You're right. While you can technically use prototypes to mimic

464
00:21:35.279 --> 00:21:39.240
<v Speaker 2>classes and inheritance from other languages, it's not really their

465
00:21:39.240 --> 00:21:43.200
<v Speaker 2>intended use. Prototypes are better suited for a pattern called

466
00:21:43.279 --> 00:21:48.279
<v Speaker 2>behavior delegation, where objects delegate tasks to other objects based

467
00:21:48.359 --> 00:21:49.359
<v Speaker 2>on their capabilities.

468
00:21:49.559 --> 00:21:52.400
<v Speaker 1>So instead of a rigid hierarchy, we have a more

469
00:21:52.440 --> 00:21:56.319
<v Speaker 1>flexible system where objects collaborate and share functionality based on

470
00:21:56.359 --> 00:21:57.440
<v Speaker 1>their roles exactly.

471
00:21:58.039 --> 00:22:00.799
<v Speaker 2>Behavior delegation is a more natural way to you prototypes,

472
00:22:01.359 --> 00:22:03.519
<v Speaker 2>and we'll explore this in more depth and a future

473
00:22:03.559 --> 00:22:04.039
<v Speaker 2>deep dive.

474
00:22:04.240 --> 00:22:06.680
<v Speaker 1>I can't wait. Wow, we've covered so much in this

475
00:22:06.759 --> 00:22:10.519
<v Speaker 1>first part, from those basic building blocks of programming to

476
00:22:10.559 --> 00:22:15.240
<v Speaker 1>the nuances of values, types, scope, functions, prototypes. We've got

477
00:22:15.240 --> 00:22:18.000
<v Speaker 1>a solid foundation for understanding how JavaScript works.

478
00:22:18.119 --> 00:22:20.720
<v Speaker 2>We have, and there's still so much more to discover.

479
00:22:21.000 --> 00:22:22.599
<v Speaker 1>I'm excited to continue this journey.

480
00:22:22.680 --> 00:22:25.720
<v Speaker 2>Me too. Welcome back to our JavaScript journey. Last time

481
00:22:25.720 --> 00:22:28.480
<v Speaker 2>I remember, we built that foundation, those core elements.

482
00:22:28.079 --> 00:22:30.359
<v Speaker 1>Of the language right, all those building blocks.

483
00:22:30.039 --> 00:22:33.920
<v Speaker 2>Exactly, and today we'll see how JavaScript actually interacts with

484
00:22:33.960 --> 00:22:36.000
<v Speaker 2>the real world, especially in web browsers.

485
00:22:36.119 --> 00:22:40.160
<v Speaker 1>I'm excited for that. So we know JavaScript makes websites

486
00:22:40.240 --> 00:22:43.200
<v Speaker 1>dynamic and all, but how does it actually work. It's

487
00:22:43.240 --> 00:22:45.519
<v Speaker 1>not like the code magically knows how to change what's

488
00:22:45.519 --> 00:22:46.599
<v Speaker 1>on the screen, right.

489
00:22:46.519 --> 00:22:50.279
<v Speaker 2>No magic involved. Yeah, think of it this way. JavaScript

490
00:22:50.319 --> 00:22:53.119
<v Speaker 2>is given a set of tools by the browser. Okay,

491
00:22:53.240 --> 00:22:56.960
<v Speaker 2>these tools they're called host objects and APIs. They're like

492
00:22:57.039 --> 00:22:59.920
<v Speaker 2>special gadgets for interacting with the web page.

493
00:23:00.079 --> 00:23:04.400
<v Speaker 1>So JavaScript gets a toolbox specifically for web development. Exactly

494
00:23:04.440 --> 00:23:06.079
<v Speaker 1>what kind of tools are we talking about?

495
00:23:06.119 --> 00:23:08.960
<v Speaker 2>One of the most important is the document object. It

496
00:23:09.000 --> 00:23:10.559
<v Speaker 2>represents the web page itself.

497
00:23:10.799 --> 00:23:11.039
<v Speaker 1>Okay.

498
00:23:11.240 --> 00:23:15.079
<v Speaker 2>Through this object, JavaScript can access all the elements on

499
00:23:15.119 --> 00:23:17.599
<v Speaker 2>the page, headings, paragraphs, images, you name it.

500
00:23:17.759 --> 00:23:20.480
<v Speaker 1>So, like if I wanted to change the text of

501
00:23:20.480 --> 00:23:23.680
<v Speaker 1>a heading when someone clicks a button, JavaScript could do

502
00:23:23.759 --> 00:23:26.200
<v Speaker 1>that through this document object exactly.

503
00:23:26.519 --> 00:23:29.960
<v Speaker 2>Host objects provide methods or actions that JavaScript can use.

504
00:23:30.440 --> 00:23:34.039
<v Speaker 2>For example, document dot get element BID. That's a method.

505
00:23:34.359 --> 00:23:36.519
<v Speaker 2>It lets you grab a specific element by its ID.

506
00:23:36.839 --> 00:23:38.839
<v Speaker 2>Once you have the element, you can do all sorts

507
00:23:38.880 --> 00:23:41.839
<v Speaker 2>of things, change its content, style or even make it disappear.

508
00:23:42.039 --> 00:23:46.599
<v Speaker 1>That's pretty amazing. So it's like JavaScript has a remote control.

509
00:23:46.279 --> 00:23:48.359
<v Speaker 2>For the web page, perfect idiology.

510
00:23:48.000 --> 00:23:51.240
<v Speaker 1>And it can manipulate elements with pinpoint accuracy. What are

511
00:23:51.240 --> 00:23:54.599
<v Speaker 1>some other examples of these remote control actions?

512
00:23:54.759 --> 00:23:56.839
<v Speaker 2>Think about those interactive maps you see online.

513
00:23:56.920 --> 00:23:57.799
<v Speaker 1>Yeah, they're so cool.

514
00:23:57.920 --> 00:24:01.160
<v Speaker 2>JavaScript uses host objects to respect onto mouse clicks or

515
00:24:01.160 --> 00:24:04.200
<v Speaker 2>scrolls zooming in and out, or displaying information about a

516
00:24:04.200 --> 00:24:07.400
<v Speaker 2>location right, or those cool animations you know where things

517
00:24:07.440 --> 00:24:08.279
<v Speaker 2>move around smooth.

518
00:24:08.319 --> 00:24:09.279
<v Speaker 1>Okay, I love those.

519
00:24:09.559 --> 00:24:14.079
<v Speaker 2>JavaScript can change in elements, position, size, color, over time,

520
00:24:14.400 --> 00:24:15.400
<v Speaker 2>creating those effects.

521
00:24:15.599 --> 00:24:18.200
<v Speaker 1>So it's not just manipulating static elements, it's bringing the

522
00:24:18.359 --> 00:24:22.319
<v Speaker 1>page to life. This is awesome. What about fetching data

523
00:24:22.359 --> 00:24:26.759
<v Speaker 1>from other sources, like loading news articles or updating stock prices?

524
00:24:26.920 --> 00:24:28.759
<v Speaker 1>How does JavaScript handle that?

525
00:24:28.759 --> 00:24:31.240
<v Speaker 2>That's where APIs come in. Okay, think of them as

526
00:24:31.240 --> 00:24:36.200
<v Speaker 2>communication channels. For example, the fetch API, let's JavaScript send

527
00:24:36.440 --> 00:24:39.480
<v Speaker 2>requests to a server and get data back.

528
00:24:39.640 --> 00:24:40.039
<v Speaker 1>Okay.

529
00:24:40.319 --> 00:24:43.079
<v Speaker 2>Like imagine an online store. When you add something to

530
00:24:43.160 --> 00:24:47.359
<v Speaker 2>your cart, JavaScript might use the fetch API to update

531
00:24:47.400 --> 00:24:48.559
<v Speaker 2>the server with your choices.

532
00:24:48.680 --> 00:24:50.160
<v Speaker 1>So it's coordinating behind.

533
00:24:49.839 --> 00:24:54.880
<v Speaker 2>The scenes exactly. This interplay between JavaScript host objects and APIs.

534
00:24:55.200 --> 00:24:57.839
<v Speaker 2>It's what makes web development so dynamic.

535
00:24:58.039 --> 00:25:01.839
<v Speaker 1>That's amazing. Okay, let's shift gears back to the core

536
00:25:02.079 --> 00:25:05.039
<v Speaker 1>JavaScript language for a bit. We talked about how JavaScript

537
00:25:05.039 --> 00:25:08.759
<v Speaker 1>can handle different types of data like numbers, strings, booleans,

538
00:25:09.400 --> 00:25:12.640
<v Speaker 1>But what about collections of data, Like if I wanted

539
00:25:12.680 --> 00:25:14.960
<v Speaker 1>to store a list of items or a set of

540
00:25:15.039 --> 00:25:16.759
<v Speaker 1>user preferences, how would I do that?

541
00:25:16.759 --> 00:25:19.559
<v Speaker 2>That's where arrays and objects come in. There are two

542
00:25:19.599 --> 00:25:21.680
<v Speaker 2>fundamental data structures in javascripts.

543
00:25:21.680 --> 00:25:22.680
<v Speaker 1>Okay, I'm ready for those.

544
00:25:22.759 --> 00:25:26.240
<v Speaker 2>An array. Imagine like a numbered list. Each item can

545
00:25:26.279 --> 00:25:29.599
<v Speaker 2>be anything a number, a string, another array, even a function.

546
00:25:29.920 --> 00:25:33.680
<v Speaker 1>So it's like my grocery list. I write down milk, eggs, bread,

547
00:25:33.839 --> 00:25:35.960
<v Speaker 1>maybe even a note to pick up the dry cleaning.

548
00:25:36.160 --> 00:25:38.839
<v Speaker 2>You got it. A. Rays are super useful for storing

549
00:25:38.839 --> 00:25:41.319
<v Speaker 2>and manipulating collections of data in JavaScript.

550
00:25:41.440 --> 00:25:43.559
<v Speaker 1>Awesome. And what about objects? How do those work?

551
00:25:43.720 --> 00:25:46.960
<v Speaker 2>Objects are more like dictionaries. They store data as key

552
00:25:47.079 --> 00:25:47.880
<v Speaker 2>value pairs.

553
00:25:48.079 --> 00:25:49.759
<v Speaker 1>Key value pairs are each.

554
00:25:49.640 --> 00:25:52.400
<v Speaker 2>Key is a unique identifier like a word in the dictionary,

555
00:25:53.000 --> 00:25:56.680
<v Speaker 2>and each values the associated information like the definition.

556
00:25:57.359 --> 00:26:02.319
<v Speaker 1>So objects are great for representing things that have multiple attributes.

557
00:26:01.799 --> 00:26:04.119
<v Speaker 2>Exactly like a user profile. It could be an object

558
00:26:04.119 --> 00:26:09.319
<v Speaker 2>with keys like name, email, age, and the values would

559
00:26:09.319 --> 00:26:10.319
<v Speaker 2>be the actual information.

560
00:26:10.599 --> 00:26:14.400
<v Speaker 1>Makes perfect sense. So arrays are like ordered lists objects

561
00:26:14.519 --> 00:26:18.200
<v Speaker 1>or like dictionaries, both really useful for managing data precisely.

562
00:26:18.279 --> 00:26:20.880
<v Speaker 2>Now, remember we talked about regular expressions briefly.

563
00:26:21.000 --> 00:26:22.880
<v Speaker 1>Yeah, they sounded a bit intimidating.

564
00:26:22.960 --> 00:26:26.519
<v Speaker 2>They could seem that way, but they're incredibly powerful. Imagine

565
00:26:26.559 --> 00:26:30.839
<v Speaker 2>you're searching for a specific word in a massive document. Okay, yeah,

566
00:26:31.079 --> 00:26:34.359
<v Speaker 2>a regular expression or rejects is like a super powered

567
00:26:34.359 --> 00:26:37.440
<v Speaker 2>search tool. You can find not just exact matches, but

568
00:26:37.519 --> 00:26:38.680
<v Speaker 2>patterns within text.

569
00:26:39.200 --> 00:26:41.880
<v Speaker 1>So it's like I could search for not just cat,

570
00:26:42.039 --> 00:26:44.480
<v Speaker 1>but any word that starts with C and ends with T.

571
00:26:44.759 --> 00:26:47.160
<v Speaker 2>You got it. They use a special syntac to define

572
00:26:47.200 --> 00:26:50.240
<v Speaker 2>these patterns, which can get complex, but they're fantastic for

573
00:26:50.319 --> 00:26:52.480
<v Speaker 2>tasks like validating user input.

574
00:26:52.759 --> 00:26:56.119
<v Speaker 1>Oh, like making sure someone enters a valid email, adjusts

575
00:26:56.200 --> 00:26:57.720
<v Speaker 1>or phone number exactly.

576
00:26:58.119 --> 00:27:00.640
<v Speaker 2>Instead of writing a bunch of if statement to check

577
00:27:00.680 --> 00:27:03.279
<v Speaker 2>every part of the address, rejects can do it all

578
00:27:03.279 --> 00:27:03.839
<v Speaker 2>in one go.

579
00:27:04.119 --> 00:27:05.440
<v Speaker 1>That's way more efficient.

580
00:27:05.920 --> 00:27:08.559
<v Speaker 2>It is. Rejects can seem a bit cryptic at first,

581
00:27:08.960 --> 00:27:10.680
<v Speaker 2>but they can save you a ton of time.

582
00:27:10.839 --> 00:27:12.759
<v Speaker 1>I'm definitely going to have to explore those more. They

583
00:27:12.759 --> 00:27:15.160
<v Speaker 1>seem like a secret weapon for JavaScript developers.

584
00:27:15.160 --> 00:27:18.279
<v Speaker 2>They can be once you master them. Now let's talk

585
00:27:18.319 --> 00:27:22.640
<v Speaker 2>about something that can be surprisingly tricky, dates and times

586
00:27:22.960 --> 00:27:23.799
<v Speaker 2>in JavaScript.

587
00:27:23.880 --> 00:27:27.400
<v Speaker 1>Oh yeah, I can imagine time zones different date formats.

588
00:27:27.799 --> 00:27:28.920
<v Speaker 1>That sounds like a headache.

589
00:27:28.960 --> 00:27:32.319
<v Speaker 2>It can be, But JavaScript has a built in date object.

590
00:27:32.400 --> 00:27:35.400
<v Speaker 2>Think of it like a multifunctional calendar and clock. Okay,

591
00:27:35.440 --> 00:27:38.240
<v Speaker 2>you can create new dates, get the current date and time,

592
00:27:38.680 --> 00:27:40.880
<v Speaker 2>do calculations, format them in different ways.

593
00:27:41.039 --> 00:27:43.599
<v Speaker 1>So if I wanted to display the current date on

594
00:27:43.640 --> 00:27:46.799
<v Speaker 1>a website or calculate how much time is left until

595
00:27:46.799 --> 00:27:47.440
<v Speaker 1>an event, you.

596
00:27:47.359 --> 00:27:50.000
<v Speaker 2>Could use the date object. Yeah, but be careful. It

597
00:27:50.000 --> 00:27:52.880
<v Speaker 2>can be a bit quirky, especially with those time zones

598
00:27:52.880 --> 00:27:54.039
<v Speaker 2>in different date formats.

599
00:27:54.240 --> 00:27:56.559
<v Speaker 1>All right, good to know. I'll make sure to double

600
00:27:56.599 --> 00:27:59.480
<v Speaker 1>check everything when working with dates. What else? Should we

601
00:27:59.519 --> 00:27:59.960
<v Speaker 1>be aware of?

602
00:28:00.279 --> 00:28:03.279
<v Speaker 2>Error handling? No matter how well you write code, errors happen.

603
00:28:03.400 --> 00:28:05.400
<v Speaker 1>Oh for sure, they always seem to sneak in.

604
00:28:05.599 --> 00:28:08.480
<v Speaker 2>JavaScript has ways to handle those errors gracefully, prevent your

605
00:28:08.519 --> 00:28:10.799
<v Speaker 2>app from crashing and helps you fix the problem.

606
00:28:10.920 --> 00:28:13.160
<v Speaker 1>So it's like having a safety net. How does this

607
00:28:13.400 --> 00:28:14.839
<v Speaker 1>error handling actually work.

608
00:28:15.319 --> 00:28:19.480
<v Speaker 2>JavaScript uses exceptions. They're like alarms going off when something

609
00:28:19.519 --> 00:28:23.240
<v Speaker 2>unexpected happens. Okay, when an error occurs an exception is thrown,

610
00:28:23.559 --> 00:28:26.559
<v Speaker 2>it interrupts the normal flow. You can use try dot

611
00:28:26.599 --> 00:28:28.960
<v Speaker 2>catch blocks to catch those exceptions.

612
00:28:28.599 --> 00:28:30.680
<v Speaker 1>So it's like setting a trap exactly.

613
00:28:31.240 --> 00:28:34.119
<v Speaker 2>Inside the catch block, you can do things like log

614
00:28:34.160 --> 00:28:37.680
<v Speaker 2>the error message for debugging, display a user friendly error

615
00:28:37.680 --> 00:28:40.359
<v Speaker 2>message to the user, or maybe even try to recover

616
00:28:40.400 --> 00:28:41.759
<v Speaker 2>from the error if possible.

617
00:28:41.960 --> 00:28:43.799
<v Speaker 1>It's like having a first aid kit for those coding

618
00:28:43.839 --> 00:28:45.200
<v Speaker 1>injuries exactly.

619
00:28:45.599 --> 00:28:49.720
<v Speaker 2>Error handling is often overlooked, especially by beginners, but it's

620
00:28:49.839 --> 00:28:54.359
<v Speaker 2>essential for building reliable applications. And speaking of professional code,

621
00:28:54.440 --> 00:28:57.559
<v Speaker 2>let's talk about some best practices that'll make your JavaScript

622
00:28:57.920 --> 00:28:58.640
<v Speaker 2>really shine.

623
00:28:58.759 --> 00:29:02.559
<v Speaker 1>Oh, I'm definitely interested in that. What separates good JavaScript

624
00:29:02.559 --> 00:29:04.759
<v Speaker 1>from like, truly great JavaScript.

625
00:29:04.920 --> 00:29:06.599
<v Speaker 2>One key thing is modularity.

626
00:29:06.720 --> 00:29:07.599
<v Speaker 1>Modularity up there.

627
00:29:07.599 --> 00:29:10.960
<v Speaker 2>Breaking down your code into smaller, self contained units like

628
00:29:10.960 --> 00:29:13.400
<v Speaker 2>those lego bricks we talked about. Yeah, makes it easier

629
00:29:13.440 --> 00:29:17.240
<v Speaker 2>to understand tests, modify without causing problems elsewhere.

630
00:29:17.319 --> 00:29:19.559
<v Speaker 1>So instead of one giant mess of code, we break

631
00:29:19.559 --> 00:29:22.640
<v Speaker 1>it down into smaller, organized modules exactly.

632
00:29:23.160 --> 00:29:27.079
<v Speaker 2>Another important principle is reusability. Writing code you can use

633
00:29:27.079 --> 00:29:32.640
<v Speaker 2>in multiple places. No duplication keeps things clean, right, makes sense, functions, objects,

634
00:29:32.920 --> 00:29:35.160
<v Speaker 2>even those regular expressions we talked about, they can all

635
00:29:35.200 --> 00:29:35.799
<v Speaker 2>be reused.

636
00:29:35.880 --> 00:29:38.160
<v Speaker 1>That's way more efficient, like having a library of.

637
00:29:38.160 --> 00:29:42.240
<v Speaker 2>Pre built components exactly. And don't underestimate readability.

638
00:29:42.400 --> 00:29:44.480
<v Speaker 1>Oh, readability is super important.

639
00:29:44.559 --> 00:29:47.759
<v Speaker 2>Imagine someone else trying to understand your code, or even

640
00:29:47.799 --> 00:29:49.519
<v Speaker 2>yourself a few months down the line.

641
00:29:49.640 --> 00:29:52.519
<v Speaker 1>Yeah, I've been there. Sometimes I can't even understand my

642
00:29:52.599 --> 00:29:53.680
<v Speaker 1>own code a week later.

643
00:29:53.759 --> 00:29:56.519
<v Speaker 2>It happens to the best of us. Using clear names,

644
00:29:56.799 --> 00:30:00.000
<v Speaker 2>adding comments to explain tricky parts, and just being consider

645
00:30:00.319 --> 00:30:02.559
<v Speaker 2>with your formatting it makes a huge difference.

646
00:30:02.640 --> 00:30:05.960
<v Speaker 1>It's like writing a recipe that's actually easy to follow exactly.

647
00:30:06.519 --> 00:30:11.440
<v Speaker 2>Clarity and consistency are key. Now efficiency is also crucial.

648
00:30:11.200 --> 00:30:13.400
<v Speaker 1>Right of course, we don't want our code to be

649
00:30:13.480 --> 00:30:15.200
<v Speaker 1>slow and clunky exactly.

650
00:30:15.720 --> 00:30:18.720
<v Speaker 2>Just like a good recipe uses the right techniques, efficient

651
00:30:18.799 --> 00:30:23.160
<v Speaker 2>JavaScript code performs well without hogging resources makes sense.

652
00:30:23.839 --> 00:30:28.400
<v Speaker 1>So choosing the right data structures, avoiding unnecessary calculations, being

653
00:30:28.440 --> 00:30:30.640
<v Speaker 1>mindful of performance in general all important.

654
00:30:31.200 --> 00:30:34.279
<v Speaker 2>And to help you write better JavaScript more efficiently, let's

655
00:30:34.319 --> 00:30:34.960
<v Speaker 2>talk tools.

656
00:30:35.240 --> 00:30:37.720
<v Speaker 1>Oh, yes, tools are essential.

657
00:30:37.960 --> 00:30:41.799
<v Speaker 2>First up, code editors. They're like high tech typewriters for code,

658
00:30:41.880 --> 00:30:44.599
<v Speaker 2>so not just notepad, no, No. Code editors are packed

659
00:30:44.599 --> 00:30:47.279
<v Speaker 2>with features that make your life easier, like what like

660
00:30:47.319 --> 00:30:50.039
<v Speaker 2>syntax highlighting, which colors different parts of your code to

661
00:30:50.039 --> 00:30:50.880
<v Speaker 2>make it more readable.

662
00:30:50.920 --> 00:30:51.799
<v Speaker 1>That would be helpful.

663
00:30:52.079 --> 00:30:55.640
<v Speaker 2>And code completion suggests code snippets as you type, saving

664
00:30:55.640 --> 00:30:57.039
<v Speaker 2>you time and typos.

665
00:30:57.279 --> 00:31:00.240
<v Speaker 1>Wow, that would save me a lot of frustration. Are

666
00:31:00.319 --> 00:31:02.160
<v Speaker 1>there any code editors you recommend?

667
00:31:02.240 --> 00:31:06.240
<v Speaker 2>Some popular choices are Visual Studio, Code, Sublime Text, and Atom.

668
00:31:06.640 --> 00:31:08.480
<v Speaker 2>They're all very customizable.

669
00:31:08.559 --> 00:31:11.640
<v Speaker 1>Sounds like there's something for everyone. What other tools should

670
00:31:11.640 --> 00:31:13.359
<v Speaker 1>every JavaScript developer know about?

671
00:31:13.599 --> 00:31:15.960
<v Speaker 2>Version control? Absolutely essential?

672
00:31:16.079 --> 00:31:16.880
<v Speaker 1>Version control?

673
00:31:16.960 --> 00:31:19.799
<v Speaker 2>Okay. Imagine you're working on a project, make a bunch

674
00:31:19.880 --> 00:31:22.240
<v Speaker 2>of changes, then realize you've messed up big time.

675
00:31:22.400 --> 00:31:25.079
<v Speaker 1>Oh, I've been there more times than i'd like to admit.

676
00:31:25.359 --> 00:31:28.559
<v Speaker 2>Version control using tools like get lets you track every

677
00:31:28.640 --> 00:31:31.559
<v Speaker 2>change and revert back to previous versions if needed.

678
00:31:31.599 --> 00:31:33.799
<v Speaker 1>It's like a time machine for my code exactly.

679
00:31:34.160 --> 00:31:37.880
<v Speaker 2>Plus get makes collaborations so much easier. You can merge changes,

680
00:31:38.039 --> 00:31:39.400
<v Speaker 2>keep everyone on the same page.

681
00:31:39.440 --> 00:31:42.319
<v Speaker 1>That's a must have for team projects. Now you mentioned

682
00:31:42.319 --> 00:31:45.839
<v Speaker 1>something about test driven development before or TDD. Can you

683
00:31:45.880 --> 00:31:47.000
<v Speaker 1>explain that a bit more?

684
00:31:47.240 --> 00:31:49.880
<v Speaker 2>TDD is a different way of thinking about coding. Instead

685
00:31:49.880 --> 00:31:52.759
<v Speaker 2>of writing code first and then testing it, you write

686
00:31:52.759 --> 00:31:53.559
<v Speaker 2>the test first.

687
00:31:53.880 --> 00:31:56.160
<v Speaker 1>Wait, so I'm writing tests for code that doesn't even

688
00:31:56.200 --> 00:31:57.759
<v Speaker 1>exist yet. How does that work?

689
00:31:57.920 --> 00:32:00.039
<v Speaker 2>I know it sounds strange, but it forces you to

690
00:31:59.880 --> 00:32:03.880
<v Speaker 2>think through what your code should do before you write it,

691
00:32:03.920 --> 00:32:07.880
<v Speaker 2>helps ensure it meets those requirements, reduces bugs, and makes

692
00:32:07.880 --> 00:32:09.440
<v Speaker 2>it easier to maintain later on.

693
00:32:09.839 --> 00:32:12.240
<v Speaker 1>So it's like building a house with the blueprints already

694
00:32:12.279 --> 00:32:13.920
<v Speaker 1>laid out, instead of just winging it.

695
00:32:14.079 --> 00:32:17.880
<v Speaker 2>Exactly, you're thinking ahead. And then there's linting. Linting, okaylinters

696
00:32:18.200 --> 00:32:21.920
<v Speaker 2>They analyze your code for potential errors, style violations, things

697
00:32:21.960 --> 00:32:22.279
<v Speaker 2>like that.

698
00:32:22.400 --> 00:32:24.960
<v Speaker 1>So like a grammar checker for my code exactly.

699
00:32:25.519 --> 00:32:29.359
<v Speaker 2>Popular JavaScript lnters like es LNT can be integrated into

700
00:32:29.359 --> 00:32:30.000
<v Speaker 2>your workflow.

701
00:32:30.160 --> 00:32:33.519
<v Speaker 1>That sounds super helpful. Catches those little mistakes before they

702
00:32:33.559 --> 00:32:34.680
<v Speaker 1>become big problems.

703
00:32:34.759 --> 00:32:37.640
<v Speaker 2>Exactly. We've covered so many tools and techniques today.

704
00:32:37.759 --> 00:32:39.440
<v Speaker 1>I know it's a lot to take in, but in

705
00:32:39.480 --> 00:32:40.000
<v Speaker 1>a good way.

706
00:32:40.079 --> 00:32:43.200
<v Speaker 2>It's all about building those skills step by step. The

707
00:32:43.240 --> 00:32:46.839
<v Speaker 2>most important thing is to keep practicing, exploring, and never

708
00:32:46.880 --> 00:32:47.519
<v Speaker 2>stop learning.

709
00:32:47.960 --> 00:32:52.319
<v Speaker 1>Great advice. I'm feeling inspired to dive even deeper into JavaScript.

710
00:32:52.440 --> 00:32:53.119
<v Speaker 2>That's the spirit.

711
00:32:53.279 --> 00:32:55.960
<v Speaker 1>Welcome back to the deep dive. We've come a long way,

712
00:32:56.319 --> 00:32:59.240
<v Speaker 1>you know. We've gone through the fundamentals of JavaScript, looked

713
00:32:59.279 --> 00:33:01.640
<v Speaker 1>at how it works with web browsers, and even discovered

714
00:33:01.640 --> 00:33:04.279
<v Speaker 1>some pretty powerful tools and techniques.

715
00:33:04.640 --> 00:33:06.200
<v Speaker 2>Been quite a journey, it has.

716
00:33:06.839 --> 00:33:11.319
<v Speaker 1>But now it's time to like really unlock the potential

717
00:33:11.519 --> 00:33:15.599
<v Speaker 1>of JavaScript. You know, we're talking advanced concepts, the kind

718
00:33:15.759 --> 00:33:17.920
<v Speaker 1>that'll take your skills to the next level.

719
00:33:18.039 --> 00:33:20.359
<v Speaker 2>That's right. Today we're venturing into the exciting world of

720
00:33:20.440 --> 00:33:25.039
<v Speaker 2>functional programming. Functional programming, okay, ready, it's a paradigm that's,

721
00:33:25.279 --> 00:33:28.480
<v Speaker 2>you know, really gaining popularity in the JavaScript world.

722
00:33:28.480 --> 00:33:29.519
<v Speaker 1>I've heard about it. Yeah.

723
00:33:29.599 --> 00:33:35.000
<v Speaker 2>It emphasizes things like immutability, pure functions, and higher order functions.

724
00:33:35.039 --> 00:33:37.440
<v Speaker 1>Okay, those terms sound a little intimidating. I'm not going

725
00:33:37.480 --> 00:33:38.759
<v Speaker 1>to like, can you break them down for me?

726
00:33:38.880 --> 00:33:42.640
<v Speaker 2>Of course, let's start with a mutability. Basically, it means data,

727
00:33:42.759 --> 00:33:45.039
<v Speaker 2>once you create it shouldn't be changed.

728
00:33:45.200 --> 00:33:45.480
<v Speaker 1>Okay.

729
00:33:45.799 --> 00:33:49.640
<v Speaker 2>Instead of modifying existing values, you create new ones based

730
00:33:49.680 --> 00:33:52.519
<v Speaker 2>on the old ones. It's like working with building blocks,

731
00:33:52.559 --> 00:33:55.200
<v Speaker 2>you know, once they're made, you can't alter them, so.

732
00:33:55.160 --> 00:33:59.039
<v Speaker 1>You can build different structures, but the blocks themselves stay

733
00:33:59.039 --> 00:34:00.160
<v Speaker 1>the same exactly.

734
00:34:00.279 --> 00:34:03.200
<v Speaker 2>It helps prevent unexpected changes, makes the code.

735
00:34:02.960 --> 00:34:06.400
<v Speaker 1>More predictable, right right, I see the benefit there. What

736
00:34:06.519 --> 00:34:07.839
<v Speaker 1>about pure functions?

737
00:34:08.079 --> 00:34:10.719
<v Speaker 2>Pure functions they always give you the same output for

738
00:34:10.760 --> 00:34:13.599
<v Speaker 2>a given input, no side effects. Okay, They don't mess

739
00:34:13.639 --> 00:34:16.079
<v Speaker 2>with any external state or data that might change.

740
00:34:16.159 --> 00:34:19.679
<v Speaker 1>So like a math function, it's pure right because two

741
00:34:19.719 --> 00:34:21.280
<v Speaker 1>plus two will always be four.

742
00:34:21.119 --> 00:34:25.599
<v Speaker 2>No matter what exactly, predictable, reliable, easy to test, got it?

743
00:34:26.199 --> 00:34:29.599
<v Speaker 1>And what about higher order functions? Those sounded pretty complex?

744
00:34:29.880 --> 00:34:32.280
<v Speaker 2>They can seem that way at first. They're functions. They

745
00:34:32.280 --> 00:34:35.400
<v Speaker 2>can take other functions as arguments or even return functions

746
00:34:35.400 --> 00:34:36.039
<v Speaker 2>as their result.

747
00:34:36.119 --> 00:34:38.320
<v Speaker 1>Okay, my brain's starting to bend a little. Can you

748
00:34:38.360 --> 00:34:39.719
<v Speaker 1>give me a real world example.

749
00:34:39.800 --> 00:34:41.920
<v Speaker 2>Sure. Imagine you have a list of numbers and you

750
00:34:41.960 --> 00:34:43.440
<v Speaker 2>want to filter out all the even numbers.

751
00:34:43.480 --> 00:34:44.119
<v Speaker 1>Okay, yeah.

752
00:34:44.199 --> 00:34:46.360
<v Speaker 2>Instead of writing a loop, you could use a higher

753
00:34:46.440 --> 00:34:49.960
<v Speaker 2>order function like filter. You'd give filter another function that

754
00:34:50.000 --> 00:34:52.679
<v Speaker 2>defines the criteria for an even number, and filter takes

755
00:34:52.719 --> 00:34:55.719
<v Speaker 2>care of the rest, applies that function to each element,

756
00:34:55.920 --> 00:34:58.199
<v Speaker 2>and gives you back a new list with only the

757
00:34:58.280 --> 00:34:59.039
<v Speaker 2>even numbers.

758
00:34:59.280 --> 00:35:02.000
<v Speaker 1>So it's like, how having a specialized machine that can

759
00:35:02.079 --> 00:35:04.840
<v Speaker 1>process those numbers without me having to do it manually.

760
00:35:05.360 --> 00:35:06.880
<v Speaker 2>That's a great way to think about it. They give

761
00:35:06.920 --> 00:35:09.920
<v Speaker 2>you this level of abstraction that makes your code simpler

762
00:35:10.000 --> 00:35:10.960
<v Speaker 2>and more reusable.

763
00:35:11.280 --> 00:35:15.199
<v Speaker 1>I can see how embracing these functional programming concepts could

764
00:35:15.320 --> 00:35:18.000
<v Speaker 1>lead to some pretty powerful JavaScript code.

765
00:35:18.039 --> 00:35:20.480
<v Speaker 2>It definitely can. It might take some getting used to

766
00:35:20.880 --> 00:35:22.440
<v Speaker 2>thinking about code in a different.

767
00:35:22.199 --> 00:35:25.079
<v Speaker 1>Way, yeah, I can imagine. But the benefits you mentioned,

768
00:35:25.159 --> 00:35:29.159
<v Speaker 1>like code clarity, reusability, testability, those all sound really worthwhile.

769
00:35:29.239 --> 00:35:32.280
<v Speaker 2>Absolutely. Now let's shift gears a bit and talk about

770
00:35:32.320 --> 00:35:37.519
<v Speaker 2>another essential aspect of modern JavaScript development, asynchronous programming.

771
00:35:37.800 --> 00:35:40.679
<v Speaker 1>Asynchronous programming Okay, I know this is about dealing with

772
00:35:40.760 --> 00:35:43.639
<v Speaker 1>tasks that might take some time, right, like fetching data

773
00:35:43.719 --> 00:35:45.719
<v Speaker 1>from a server or reading a file.

774
00:35:46.079 --> 00:35:50.239
<v Speaker 2>Exactly in a synchronous world, everything happens one step at

775
00:35:50.239 --> 00:35:54.199
<v Speaker 2>a time in order, but in reality, we often deal

776
00:35:54.239 --> 00:35:58.119
<v Speaker 2>with tasks that don't have an immediate answer. Asynchronous programming

777
00:35:58.199 --> 00:36:00.840
<v Speaker 2>lets us keep things running smoothly while we wait for

778
00:36:00.880 --> 00:36:02.639
<v Speaker 2>those longer tasks to finish.

779
00:36:02.840 --> 00:36:04.960
<v Speaker 1>Right. We can't just have the whole program freeze up

780
00:36:04.960 --> 00:36:06.800
<v Speaker 1>while it's waiting for something exactly.

781
00:36:07.039 --> 00:36:08.559
<v Speaker 2>Users wouldn't be very happy with that.

782
00:36:08.760 --> 00:36:12.000
<v Speaker 1>No, not at all. So how does JavaScript handle these

783
00:36:12.480 --> 00:36:13.840
<v Speaker 1>asynchronous operations?

784
00:36:14.199 --> 00:36:17.880
<v Speaker 2>Well, we talked about callbacks, right, functions that get executed

785
00:36:17.920 --> 00:36:18.880
<v Speaker 2>when a task is done.

786
00:36:19.000 --> 00:36:21.360
<v Speaker 1>Yeah, they're like sending a message and waiting for a reply.

787
00:36:21.559 --> 00:36:23.599
<v Speaker 2>That's a good way to think about it. But there

788
00:36:23.599 --> 00:36:27.039
<v Speaker 2>are other approaches as well, like promises and a syncowate.

789
00:36:27.360 --> 00:36:29.360
<v Speaker 1>Oh yeah, I've heard about those. Can you explain what

790
00:36:29.400 --> 00:36:30.039
<v Speaker 1>they're all about.

791
00:36:30.320 --> 00:36:34.159
<v Speaker 2>Promises offer a more structured way to handle asynchronous stuff.

792
00:36:34.719 --> 00:36:37.519
<v Speaker 2>Think of them like making your reservation at a restaurant.

793
00:36:37.679 --> 00:36:40.199
<v Speaker 2>You get a promise that your table will be ready

794
00:36:40.239 --> 00:36:42.920
<v Speaker 2>at a certain time. You can then do other things

795
00:36:43.000 --> 00:36:44.960
<v Speaker 2>and come back when the promise is fulfilled.

796
00:36:45.079 --> 00:36:48.519
<v Speaker 1>Okay, so the promise represents the eventual result of that operation.

797
00:36:48.920 --> 00:36:50.159
<v Speaker 1>Makes sense exactly.

798
00:36:50.519 --> 00:36:53.360
<v Speaker 2>And then we have a syncowate, which builds on promises,

799
00:36:53.599 --> 00:36:56.199
<v Speaker 2>lets you write a synchronous code that almost looks like

800
00:36:56.199 --> 00:36:58.960
<v Speaker 2>synchronous code, way easier to read and understand.

801
00:36:59.119 --> 00:37:01.840
<v Speaker 1>So asyncow is like taking care of all that behind

802
00:37:01.840 --> 00:37:04.400
<v Speaker 1>the scenes stuff, making it seem like everything happens instantly.

803
00:37:04.480 --> 00:37:07.960
<v Speaker 2>Pretty much. It simplifies asynchronous code and helps avoid that

804
00:37:08.280 --> 00:37:11.880
<v Speaker 2>callback hell. You know, with all those nested callbacks.

805
00:37:11.400 --> 00:37:12.880
<v Speaker 1>Callback hell, that sounds scary.

806
00:37:13.039 --> 00:37:16.559
<v Speaker 2>It can get messy. Okay, Before we wrap up our

807
00:37:16.639 --> 00:37:21.199
<v Speaker 2>JavaScript journey, I'm curious about what's on the horizon. What

808
00:37:21.320 --> 00:37:24.920
<v Speaker 2>emerging trends should JavaScript developers be keeping an eye on.

809
00:37:25.079 --> 00:37:27.000
<v Speaker 1>Oh, that's a great question. What's coming next?

810
00:37:27.199 --> 00:37:30.480
<v Speaker 2>One exciting development is web assembly. Web assembly it's a

811
00:37:30.480 --> 00:37:34.960
<v Speaker 2>low level bytecode format promises near native performance for web apps.

812
00:37:35.239 --> 00:37:38.199
<v Speaker 1>Near native performance. Wow, what does that mean? Exactly?

813
00:37:38.519 --> 00:37:41.920
<v Speaker 2>Imagine being able to run really complex applications like games

814
00:37:42.000 --> 00:37:45.239
<v Speaker 2>or simulations right in the browser with performance close to

815
00:37:45.280 --> 00:37:46.039
<v Speaker 2>desktop apps.

816
00:37:46.239 --> 00:37:49.559
<v Speaker 1>That's incredible. So does web assembly replace JavaScript?

817
00:37:49.840 --> 00:37:53.480
<v Speaker 2>No, it complements it. We can write performance critical code

818
00:37:53.480 --> 00:37:57.199
<v Speaker 2>in other languages like C plus plus or Rust, compile

819
00:37:57.280 --> 00:38:00.000
<v Speaker 2>them to web assembly, and run them alongside JavaScript.

820
00:38:00.199 --> 00:38:03.360
<v Speaker 1>So like having a turbocharge engine to boost performance for

821
00:38:03.400 --> 00:38:04.480
<v Speaker 1>specific tasks.

822
00:38:04.760 --> 00:38:08.480
<v Speaker 2>Exactly. It opens up so many possibilities for web applications.

823
00:38:09.119 --> 00:38:12.960
<v Speaker 2>Another trend is typescript. Typescript it's like a superset of JavaScript,

824
00:38:13.400 --> 00:38:15.480
<v Speaker 2>adds optional static typing.

825
00:38:15.519 --> 00:38:18.480
<v Speaker 1>So we can specify the types of our variables and

826
00:38:18.519 --> 00:38:20.079
<v Speaker 1>function parameters ahead.

827
00:38:19.800 --> 00:38:23.360
<v Speaker 2>Of time exactly. Healthcatch errors early on makes your code

828
00:38:23.360 --> 00:38:27.119
<v Speaker 2>more robust, especially in larger projects. It's like that stricter

829
00:38:27.159 --> 00:38:30.480
<v Speaker 2>building inspector you mentioned checking for flaws in the blueprints.

830
00:38:30.559 --> 00:38:33.719
<v Speaker 1>I like that analogy. So Typescript's like adding extra safety

831
00:38:33.760 --> 00:38:35.320
<v Speaker 1>and reliability.

832
00:38:34.679 --> 00:38:38.360
<v Speaker 2>Exactly, and it's becoming super popular, especially for bigger applications.

833
00:38:38.440 --> 00:38:41.599
<v Speaker 1>Makes sense. It integrates with existing jawscript code.

834
00:38:41.400 --> 00:38:44.280
<v Speaker 2>Too, right, it does. You can adopt it gradually. Another

835
00:38:44.280 --> 00:38:46.039
<v Speaker 2>trend is serverless architectures.

836
00:38:46.199 --> 00:38:48.039
<v Speaker 1>Serverless what's that all about.

837
00:38:48.199 --> 00:38:50.800
<v Speaker 2>It's a way to deploy and run your code without

838
00:38:50.800 --> 00:38:51.960
<v Speaker 2>having to manage servers.

839
00:38:52.079 --> 00:38:54.639
<v Speaker 1>Wait, so, no more setting up and configuring servers.

840
00:38:55.000 --> 00:38:57.960
<v Speaker 2>Cloud providers handle all that for you. You focus on the

841
00:38:57.960 --> 00:39:00.719
<v Speaker 2>logic of your app. They handle the infrastructure and scaling.

842
00:39:00.880 --> 00:39:03.840
<v Speaker 1>That sounds amazing like having a team of invisible engineers

843
00:39:03.880 --> 00:39:05.599
<v Speaker 1>working behind the scenes exactly.

844
00:39:05.960 --> 00:39:09.159
<v Speaker 2>And it's a great fit for JavaScript, especially for web development.

845
00:39:09.559 --> 00:39:10.719
<v Speaker 2>Definitely worth exploring.

846
00:39:11.039 --> 00:39:13.679
<v Speaker 1>Wow, this is incredible. We've covered so much ground in

847
00:39:13.719 --> 00:39:16.079
<v Speaker 1>this deep dive. It feels like I've gained a whole

848
00:39:16.119 --> 00:39:20.519
<v Speaker 1>new understanding of JavaScript. It's so versatile and powerful.

849
00:39:20.159 --> 00:39:23.639
<v Speaker 2>It is, And remember this is just the beginning. Keep exploring,

850
00:39:23.800 --> 00:39:26.360
<v Speaker 2>keep learning, keep that curiosity alive.

851
00:39:26.599 --> 00:39:29.360
<v Speaker 1>That's great advice. Thank you so much for guiding us

852
00:39:29.400 --> 00:39:32.679
<v Speaker 1>through this incredible journey into the world of JavaScript. We

853
00:39:32.719 --> 00:39:35.440
<v Speaker 1>hope our listeners feel inspired to keep learning and create

854
00:39:35.519 --> 00:39:37.280
<v Speaker 1>amazing things with this language.

855
00:39:37.360 --> 00:39:39.559
<v Speaker 2>We hope so too, and we'd love to hear about

856
00:39:39.559 --> 00:39:43.920
<v Speaker 2>your JavaScript adventures. Share your projects, your insights, your AHA moments.

857
00:39:44.400 --> 00:39:46.119
<v Speaker 2>Until next time, happy coding,
