WEBVTT

1
00:00:00.120 --> 00:00:02.720
<v Speaker 1>Welcome to the deep dive. Think of this as your

2
00:00:03.120 --> 00:00:05.960
<v Speaker 1>cheat sheet, maybe your shortcut to getting really well informed

3
00:00:05.960 --> 00:00:06.879
<v Speaker 1>about important stuff.

4
00:00:07.000 --> 00:00:09.679
<v Speaker 2>Yeah, we basically wade through all the information, find the

5
00:00:09.720 --> 00:00:12.279
<v Speaker 2>core ideas, and bring back what you really need to know.

6
00:00:12.519 --> 00:00:14.119
<v Speaker 3>Saves you time exactly.

7
00:00:14.560 --> 00:00:19.480
<v Speaker 1>And today we are plunging into javascripts specifically for web developers.

8
00:00:19.760 --> 00:00:22.239
<v Speaker 1>We've got a whole stack of resources here.

9
00:00:22.120 --> 00:00:25.960
<v Speaker 2>We do, covering well everything from the real basic building

10
00:00:26.000 --> 00:00:28.480
<v Speaker 2>blocks right up to the you know, the fancy new

11
00:00:28.519 --> 00:00:30.600
<v Speaker 2>browser APIs and features just emerging.

12
00:00:30.960 --> 00:00:34.039
<v Speaker 1>Right, So the mission for this deep dive pull out

13
00:00:34.039 --> 00:00:38.520
<v Speaker 1>the essential concepts, maybe some surprising details about modern JS development.

14
00:00:38.240 --> 00:00:41.000
<v Speaker 2>Give you a solid handle on it without you know,

15
00:00:41.079 --> 00:00:43.159
<v Speaker 2>drowning you in every single tiny detail.

16
00:00:43.240 --> 00:00:46.920
<v Speaker 1>Perfect. Okay, let's kick things off with something well fundamental.

17
00:00:47.200 --> 00:00:50.719
<v Speaker 1>We always hear javascripts and ECMAScript toss around. What's the

18
00:00:50.759 --> 00:00:52.000
<v Speaker 1>actual relationship there?

19
00:00:52.079 --> 00:00:56.479
<v Speaker 2>Okay, good starting point. Think of ECMAScript as the official standard.

20
00:00:56.560 --> 00:00:59.159
<v Speaker 2>It's the specificating like the rule book for how a

21
00:00:59.200 --> 00:01:03.280
<v Speaker 2>scripting language should behave the rulebook okay in JavaScript? Well,

22
00:01:03.359 --> 00:01:06.519
<v Speaker 2>JavaScript is the most well known language that actually follows

23
00:01:06.560 --> 00:01:09.079
<v Speaker 2>those rules. It implements the ECMAScript standard.

24
00:01:09.319 --> 00:01:12.680
<v Speaker 1>Ah, got it? So xmascript is the spec. JavaScript is

25
00:01:12.719 --> 00:01:14.280
<v Speaker 1>the implementation.

26
00:01:14.040 --> 00:01:19.000
<v Speaker 2>Exactly, and just like languages evolve, xmascript gets updated, new editions,

27
00:01:19.040 --> 00:01:22.439
<v Speaker 2>come out S six, S twenty twenty, whatever, adding new features,

28
00:01:22.480 --> 00:01:26.200
<v Speaker 2>refining things. JavaScript then usually catches up and implements those

29
00:01:26.280 --> 00:01:26.799
<v Speaker 2>new features.

30
00:01:26.920 --> 00:01:30.040
<v Speaker 1>Makes sense. So when we put JavaScript on a web page,

31
00:01:30.040 --> 00:01:32.719
<v Speaker 1>we use the script tags. Our sources mentioned two main

32
00:01:32.760 --> 00:01:36.359
<v Speaker 1>types these days, the old text JavaScript and the newer module.

33
00:01:36.680 --> 00:01:40.040
<v Speaker 2>What's the key difference, right, So script type text JavaScript,

34
00:01:40.079 --> 00:01:43.000
<v Speaker 2>that's the classic way. Code inside there runs in well

35
00:01:43.079 --> 00:01:44.840
<v Speaker 2>basically the global scope for that script.

36
00:01:44.879 --> 00:01:46.120
<v Speaker 1>Everything together pretty much.

37
00:01:46.200 --> 00:01:48.719
<v Speaker 2>But script type module is different. I came with EES six.

38
00:01:48.920 --> 00:01:51.239
<v Speaker 2>It tells the browser, hey, treat this code as a

39
00:01:51.280 --> 00:01:53.000
<v Speaker 2>proper ECMAScript.

40
00:01:52.519 --> 00:01:53.920
<v Speaker 1>Module and what does that let us do?

41
00:01:54.079 --> 00:01:56.840
<v Speaker 2>That unlocks features like import and export, so you can

42
00:01:56.840 --> 00:02:00.599
<v Speaker 2>break your code into smaller, reusable pieces, manage dependence the cleanly.

43
00:02:00.680 --> 00:02:03.640
<v Speaker 2>It's a huge step up for organization and avoiding conflicts.

44
00:02:03.799 --> 00:02:05.840
<v Speaker 1>Right, So it stops everything from just clashing in that

45
00:02:05.920 --> 00:02:10.120
<v Speaker 1>one big global space, more organized, way, more organized.

46
00:02:09.919 --> 00:02:13.759
<v Speaker 2>With separate offices communicating properly instead of one giant noisy room.

47
00:02:13.879 --> 00:02:18.759
<v Speaker 1>Good analogy. Okay, moving into the code itself, comments, essential notes.

48
00:02:18.840 --> 00:02:19.000
<v Speaker 2>Right.

49
00:02:19.439 --> 00:02:22.080
<v Speaker 1>Our sources mentioned the C style comments.

50
00:02:22.280 --> 00:02:25.199
<v Speaker 2>Yep, JavaScript uses the familiar SEA style you've got for

51
00:02:25.319 --> 00:02:28.120
<v Speaker 2>single line comments. Anything after that on the line is ignored.

52
00:02:28.199 --> 00:02:30.000
<v Speaker 1>And the multi line ones that's.

53
00:02:29.639 --> 00:02:31.599
<v Speaker 2>To start and to end. You can put multiple lines

54
00:02:31.639 --> 00:02:34.439
<v Speaker 2>of comments between those. It was a natural fit really,

55
00:02:34.439 --> 00:02:38.479
<v Speaker 2>given JavaScript's influences and how common C style syntax was.

56
00:02:38.599 --> 00:02:42.520
<v Speaker 1>Makes sense. Keep it familiar. Now, code structure curly braces.

57
00:02:42.560 --> 00:02:45.159
<v Speaker 1>We use them everywhere, like with if statements. Are they

58
00:02:45.199 --> 00:02:47.439
<v Speaker 1>just for looks or more fundamental?

59
00:02:47.479 --> 00:02:50.680
<v Speaker 2>Oh, they're fundamental. They define code blocks. You can technically

60
00:02:50.719 --> 00:02:53.680
<v Speaker 2>omit them for a single statement after an IF or

61
00:02:53.719 --> 00:02:56.199
<v Speaker 2>a four like if condition do one thing.

62
00:02:56.319 --> 00:02:58.280
<v Speaker 3>Yeah, I've seen that, but it's really.

63
00:02:58.080 --> 00:03:01.719
<v Speaker 2>Really considered best practiced. Always use the curly braces. It

64
00:03:01.719 --> 00:03:04.479
<v Speaker 2>makes the code much easier to read and prevents subtle

65
00:03:04.479 --> 00:03:07.520
<v Speaker 2>bugs later if you add more statements to that block.

66
00:03:07.800 --> 00:03:12.639
<v Speaker 1>Good advice, Always use the braces. Okay, Variables the heart

67
00:03:12.719 --> 00:03:15.199
<v Speaker 1>of storing data. We've got the old var and the

68
00:03:15.240 --> 00:03:18.599
<v Speaker 1>newer let and constant. Let's break down the key differences,

69
00:03:18.919 --> 00:03:21.520
<v Speaker 1>scope hoisting all that stuff.

70
00:03:21.680 --> 00:03:25.400
<v Speaker 2>Right, So var it's function scoped, meaning if you declare

71
00:03:25.439 --> 00:03:29.240
<v Speaker 2>a var inside a function, it's known throughout that entire function,

72
00:03:29.360 --> 00:03:31.879
<v Speaker 2>even inside nested blocks like ifts or loops.

73
00:03:32.039 --> 00:03:34.759
<v Speaker 1>Okay, function scope and hoisting.

74
00:03:34.840 --> 00:03:37.599
<v Speaker 2>Ye, var declarations are hoisted. That means the declaration part

75
00:03:38.000 --> 00:03:40.800
<v Speaker 2>like varx is conceptually moved to the top of its

76
00:03:40.800 --> 00:03:41.919
<v Speaker 2>function scope.

77
00:03:41.800 --> 00:03:43.560
<v Speaker 1>Before the code runs just the declaration.

78
00:03:43.800 --> 00:03:46.520
<v Speaker 2>Just the declaration the assignment x equals ten stays where

79
00:03:46.520 --> 00:03:49.120
<v Speaker 2>you wrote it. This can lead to weird situations where

80
00:03:49.240 --> 00:03:51.719
<v Speaker 2>you can use a variable before its declaration appears in

81
00:03:51.719 --> 00:03:54.479
<v Speaker 2>the code, and it'll have the value undefined.

82
00:03:54.680 --> 00:03:56.479
<v Speaker 1>And you can readeclare var variables too.

83
00:03:56.599 --> 00:03:59.080
<v Speaker 2>Yep, you can write var myvar five and then later

84
00:03:59.159 --> 00:04:02.240
<v Speaker 2>varivar ten in the same scope and JavaScript is fine

85
00:04:02.240 --> 00:04:03.759
<v Speaker 2>with it, which can also cause confusion.

86
00:04:03.800 --> 00:04:06.680
<v Speaker 1>Definitely sounds like it could. So how does let improve things?

87
00:04:07.000 --> 00:04:09.680
<v Speaker 2>Let was introduced in e S six to fix these issues.

88
00:04:10.120 --> 00:04:12.879
<v Speaker 2>The big change is block scope. A LET variable is

89
00:04:12.919 --> 00:04:15.919
<v Speaker 2>only known within the specific block that curly braces words.

90
00:04:15.639 --> 00:04:18.360
<v Speaker 1>Defined, So inside an if or a for loop, it

91
00:04:18.439 --> 00:04:20.399
<v Speaker 1>only exists there exactly.

92
00:04:20.319 --> 00:04:23.920
<v Speaker 2>Much more contained, much easier to reason about. It prevents

93
00:04:23.959 --> 00:04:26.560
<v Speaker 2>accidental variable clashes between different parts of your code.

94
00:04:26.639 --> 00:04:30.319
<v Speaker 1>That sounds way better. What about hoisting and redeclaration with let.

95
00:04:30.600 --> 00:04:34.839
<v Speaker 2>Let declarations are also hoisted, but critically their initialization is not.

96
00:04:35.160 --> 00:04:38.120
<v Speaker 2>This creates something called the temporal dead zone or TDZ.

97
00:04:38.600 --> 00:04:40.720
<v Speaker 2>If you try to access a let variable before it's

98
00:04:40.720 --> 00:04:43.480
<v Speaker 2>actual declaration line in the code, you get a reference there.

99
00:04:43.720 --> 00:04:46.839
<v Speaker 1>Ah. Okay, so safer prevents using it before it's.

100
00:04:46.720 --> 00:04:49.839
<v Speaker 2>Ready, right, and you cannot redeclare a let variable within

101
00:04:49.879 --> 00:04:52.399
<v Speaker 2>the same scope. Yeah, if you try let x five

102
00:04:52.519 --> 00:04:55.079
<v Speaker 2>let x bleeds ten in the same block, you'll get

103
00:04:55.120 --> 00:04:56.680
<v Speaker 2>an error much stricter.

104
00:04:56.560 --> 00:04:59.839
<v Speaker 1>Good and then const the name implies it can't be changed.

105
00:05:00.160 --> 00:05:03.319
<v Speaker 2>Very similar to it's also block scoped has the TDZ

106
00:05:03.800 --> 00:05:05.800
<v Speaker 2>and cannot be redeclared in the same scope.

107
00:05:05.959 --> 00:05:06.920
<v Speaker 1>But the key difference.

108
00:05:07.199 --> 00:05:10.560
<v Speaker 2>You must initialize a cost variable when you declare it

109
00:05:10.639 --> 00:05:14.480
<v Speaker 2>like cost pi equals three point one four, and once assigned,

110
00:05:14.879 --> 00:05:17.839
<v Speaker 2>you cannot reassign that variable to a different value. The

111
00:05:17.879 --> 00:05:19.439
<v Speaker 2>binding is constant.

112
00:05:19.319 --> 00:05:23.040
<v Speaker 1>So pi equals three later would cause an error exactly.

113
00:05:23.560 --> 00:05:26.199
<v Speaker 2>But and this is important, if the const variable holds

114
00:05:26.199 --> 00:05:29.319
<v Speaker 2>an object or an array, you could still change the

115
00:05:29.319 --> 00:05:31.800
<v Speaker 2>contents of that object or array. You just can't make

116
00:05:31.839 --> 00:05:34.560
<v Speaker 2>the variable point to a completely new object or array.

117
00:05:34.759 --> 00:05:38.480
<v Speaker 1>Ah. Subtle but crucial distinctions. The variable binding is constant,

118
00:05:38.560 --> 00:05:42.439
<v Speaker 1>not necessarily the value itself if it's an object precisely.

119
00:05:42.439 --> 00:05:45.560
<v Speaker 2>And our sources mentioned a potential performance benefit to using

120
00:05:45.639 --> 00:05:48.240
<v Speaker 2>let and const over var, because the engine has a

121
00:05:48.240 --> 00:05:50.240
<v Speaker 2>better idea of how the variable will be used.

122
00:05:50.360 --> 00:05:53.800
<v Speaker 1>Interesting worth keeping in mind. Now, naming these variables identifiers,

123
00:05:53.879 --> 00:05:55.000
<v Speaker 1>are there strict rules?

124
00:05:55.199 --> 00:05:58.120
<v Speaker 2>Yes, identifiers have to start with a letter, an underscore,

125
00:05:58.399 --> 00:06:00.879
<v Speaker 2>or a dollar sign after the first character. You can

126
00:06:00.920 --> 00:06:02.319
<v Speaker 2>also use numbers, okay.

127
00:06:02.480 --> 00:06:04.399
<v Speaker 1>Any things you can't use definitely.

128
00:06:04.600 --> 00:06:09.199
<v Speaker 2>You can't use JavaScript keywords like if, for function, let, const, var,

129
00:06:09.399 --> 00:06:12.959
<v Speaker 2>et cetera. You also can't use reserved words words set

130
00:06:12.959 --> 00:06:16.639
<v Speaker 2>aside for future use, and the literal values true, false,

131
00:06:16.680 --> 00:06:19.480
<v Speaker 2>and null are also off limits as variable names.

132
00:06:19.720 --> 00:06:22.360
<v Speaker 1>Makes sense, don't want to confuse the language itself. Okay,

133
00:06:22.399 --> 00:06:24.680
<v Speaker 1>Let's talk data types the primitives first. These are the

134
00:06:24.759 --> 00:06:27.120
<v Speaker 1>simple fundamental types, right, the.

135
00:06:27.079 --> 00:06:30.800
<v Speaker 2>Basic building blocks. First up is number. This covers both

136
00:06:30.839 --> 00:06:34.439
<v Speaker 2>integers and floating point numbers. JavaScript doesn't really distinguish between

137
00:06:34.480 --> 00:06:36.319
<v Speaker 2>them internally in the way some other languages do.

138
00:06:36.399 --> 00:06:39.120
<v Speaker 1>Some number okay, Any special ways to write.

139
00:06:39.000 --> 00:06:42.360
<v Speaker 2>Numbers, Yeah, you can write integers in decimal obviously, but

140
00:06:42.399 --> 00:06:45.319
<v Speaker 2>also binary using a zero B prefix, octal with a

141
00:06:45.439 --> 00:06:48.879
<v Speaker 2>zero O prefix or just eleading zero in nonstrict mode,

142
00:06:48.920 --> 00:06:52.160
<v Speaker 2>which can be confusing, and hexadecimal with zero.

143
00:06:52.120 --> 00:06:54.839
<v Speaker 1>X hex is pretty common in web dev, very common.

144
00:06:55.000 --> 00:06:57.720
<v Speaker 2>And within number you also have the special values nan

145
00:06:58.720 --> 00:06:58.959
<v Speaker 2>not a.

146
00:06:59.040 --> 00:07:01.519
<v Speaker 1>Number, which can confusingly is a number type right?

147
00:07:01.639 --> 00:07:04.639
<v Speaker 2>Ah? Yes, type of nan returns number. It usually results

148
00:07:04.639 --> 00:07:07.759
<v Speaker 2>from invalid math operations like zero zero, and you have

149
00:07:07.879 --> 00:07:09.319
<v Speaker 2>infinity and into infinity.

150
00:07:09.480 --> 00:07:12.399
<v Speaker 1>Okay, And what about really really huge numbers.

151
00:07:12.560 --> 00:07:15.720
<v Speaker 2>That's where bigin comes in. It's a newer primitive type

152
00:07:15.720 --> 00:07:19.360
<v Speaker 2>designed to handle integers larger than the maximum safe integer

153
00:07:19.439 --> 00:07:22.040
<v Speaker 2>value for number, which is around two to the power

154
00:07:22.040 --> 00:07:23.199
<v Speaker 2>of fifty three minus one.

155
00:07:23.279 --> 00:07:23.839
<v Speaker 3>Wow.

156
00:07:24.279 --> 00:07:25.199
<v Speaker 1>How do you create those?

157
00:07:25.360 --> 00:07:27.319
<v Speaker 2>You append an end to the end of an integer

158
00:07:27.439 --> 00:07:30.600
<v Speaker 2>literal like one, two, three, four five n or you

159
00:07:30.720 --> 00:07:31.680
<v Speaker 2>use the big in function.

160
00:07:31.879 --> 00:07:33.120
<v Speaker 1>Any gotcha's with big inn.

161
00:07:33.279 --> 00:07:36.120
<v Speaker 2>Yeah. You can't mix biggest and number types in standard

162
00:07:36.120 --> 00:07:38.680
<v Speaker 2>arithmetic operations directly. You have to convert them, and you

163
00:07:38.680 --> 00:07:41.360
<v Speaker 2>can't use big in values with the built in math

164
00:07:41.399 --> 00:07:42.240
<v Speaker 2>object methods.

165
00:07:42.439 --> 00:07:44.720
<v Speaker 1>Good to know. Okay. Beyond numbers, we have.

166
00:07:44.759 --> 00:07:49.079
<v Speaker 2>String represents text basically a sequence of sixteen bit Unicode characters.

167
00:07:49.480 --> 00:07:53.079
<v Speaker 2>You can use single quotes, double quotes, or backticks to

168
00:07:53.160 --> 00:07:53.680
<v Speaker 2>define them.

169
00:07:53.759 --> 00:07:55.759
<v Speaker 1>Any difference between single and double quotes.

170
00:07:56.079 --> 00:08:02.000
<v Speaker 2>Functionally no, it's mostly style preference, though enable template literals,

171
00:08:02.000 --> 00:08:05.040
<v Speaker 2>which are super useful for embetting expressions directly into strings.

172
00:08:05.120 --> 00:08:07.399
<v Speaker 1>Right with the syntax very handy.

173
00:08:07.439 --> 00:08:10.319
<v Speaker 2>Next, boolean simple one can only be true or false,

174
00:08:10.639 --> 00:08:12.279
<v Speaker 2>used all the time for conditional logic.

175
00:08:12.560 --> 00:08:16.519
<v Speaker 1>Okay, and then null and undefined They seem similar but

176
00:08:16.600 --> 00:08:17.680
<v Speaker 1>aren't quite.

177
00:08:17.360 --> 00:08:21.000
<v Speaker 2>The same correct. Null is a primitive type that represents

178
00:08:21.000 --> 00:08:25.519
<v Speaker 2>the intentional absence of any object value you explicitly set

179
00:08:25.600 --> 00:08:29.639
<v Speaker 2>something to null. Undefined means a variable has been declared

180
00:08:29.920 --> 00:08:33.080
<v Speaker 2>but hasn't been assigned of value yet. It's the default state.

181
00:08:33.480 --> 00:08:35.799
<v Speaker 1>So null is I meant for this to be empty?

182
00:08:35.840 --> 00:08:38.559
<v Speaker 1>And undefined is nobody put anything here yet?

183
00:08:38.720 --> 00:08:40.840
<v Speaker 2>That's a good way to think about it. And finally,

184
00:08:40.879 --> 00:08:43.480
<v Speaker 2>among the primatives, there's symbol symbols.

185
00:08:43.600 --> 00:08:45.799
<v Speaker 1>These are unique identifiers right exactly.

186
00:08:45.919 --> 00:08:50.039
<v Speaker 2>Symbol creates a unique, immutable primitive value. Even if you

187
00:08:50.080 --> 00:08:52.600
<v Speaker 2>create two symbols with the same description, like symbol foo

188
00:08:52.639 --> 00:08:55.360
<v Speaker 2>and simple foo, they are not equal. They're unique.

189
00:08:55.399 --> 00:08:56.120
<v Speaker 1>What are they used for?

190
00:08:56.559 --> 00:08:59.120
<v Speaker 2>Often? Uses keys for object properties when you want to

191
00:08:59.159 --> 00:09:03.320
<v Speaker 2>avoid potential clashes with other properties or library code. There's

192
00:09:03.360 --> 00:09:06.519
<v Speaker 2>also symbol dot four key, which creates or retrieve symbols

193
00:09:06.519 --> 00:09:09.600
<v Speaker 2>from a global registry. So symbol dot for food.

194
00:09:10.000 --> 00:09:13.399
<v Speaker 1>Interesting. Do they show up in normal object iteration? Not?

195
00:09:13.600 --> 00:09:16.320
<v Speaker 2>Usually they aren't enumerated by four dot. In loops, you

196
00:09:16.360 --> 00:09:19.360
<v Speaker 2>need specific methods like object dot get town property symbols,

197
00:09:19.720 --> 00:09:21.679
<v Speaker 2>or reflect dot own keys to access them.

198
00:09:21.720 --> 00:09:23.559
<v Speaker 1>Okay, and there are built in symbols.

199
00:09:23.240 --> 00:09:26.879
<v Speaker 2>Too, Yes, well known symbols like symbol dot iterator, symbol

200
00:09:26.879 --> 00:09:29.799
<v Speaker 2>dot replace, symbol dot search. These allow you to hook

201
00:09:29.840 --> 00:09:31.600
<v Speaker 2>into fundamental language behaviors.

202
00:09:31.720 --> 00:09:35.360
<v Speaker 1>That's a lot of primitives. Okay, let's talk operators doing

203
00:09:35.399 --> 00:09:39.200
<v Speaker 1>things with these values basic math like and seem straightforward.

204
00:09:39.480 --> 00:09:43.039
<v Speaker 1>But what about those bitwise operators? When do we use those?

205
00:09:43.240 --> 00:09:45.879
<v Speaker 2>Right? So, multiplication and division have rules for nan and

206
00:09:45.960 --> 00:09:49.720
<v Speaker 2>infinity like infinity zeros in NAN, but the bitwise operators

207
00:09:49.879 --> 00:09:53.720
<v Speaker 2>and D or xo R not marriot left shift signed

208
00:09:53.759 --> 00:09:56.799
<v Speaker 2>right shift, unsigned right shift. They operate directly on the

209
00:09:56.799 --> 00:09:58.440
<v Speaker 2>binary representation of numbers.

210
00:09:58.440 --> 00:09:59.799
<v Speaker 1>Lower level stuff, yeah.

211
00:09:59.639 --> 00:10:01.759
<v Speaker 2>Very low level. You might use them for things like

212
00:10:01.919 --> 00:10:05.799
<v Speaker 2>manipulating flags stored in a single number. Performance critical calculations,

213
00:10:05.799 --> 00:10:09.559
<v Speaker 2>maybe graphics or network protocol work where you're packing data efficiently.

214
00:10:09.759 --> 00:10:12.120
<v Speaker 1>So left shift multiplies by powers of two.

215
00:10:12.159 --> 00:10:15.120
<v Speaker 2>Correct and preserves the sign signed right shift divides by

216
00:10:15.159 --> 00:10:18.240
<v Speaker 2>powers of two, also preserving the sign. Unsigned right shifts

217
00:10:18.240 --> 00:10:20.840
<v Speaker 2>also divides, but always fills with zeros on the left,

218
00:10:20.840 --> 00:10:24.279
<v Speaker 2>so the result is always non negative. Not everyday tools

219
00:10:24.279 --> 00:10:26.240
<v Speaker 2>for most web devs, but good to know they.

220
00:10:26.120 --> 00:10:30.879
<v Speaker 1>Exist definitely now the sources mentioned the with statement sounds old, it.

221
00:10:30.799 --> 00:10:34.440
<v Speaker 2>Is and definitely deprecated and forbidden in strict mode. Its

222
00:10:34.480 --> 00:10:38.399
<v Speaker 2>idea was to shorten access to object properties like with

223
00:10:38.639 --> 00:10:42.960
<v Speaker 2>document dot location instead of repeating document dot location.

224
00:10:43.360 --> 00:10:44.039
<v Speaker 1>Why is it bad?

225
00:10:44.240 --> 00:10:46.799
<v Speaker 2>It makes code really hard to understand because it's unclear

226
00:10:46.879 --> 00:10:50.200
<v Speaker 2>where variables are coming from. Are they local, global, or

227
00:10:50.559 --> 00:10:53.840
<v Speaker 2>from the with object And it kills performance because the

228
00:10:53.840 --> 00:10:55.639
<v Speaker 2>engine can't easily optimize lookups.

229
00:10:55.799 --> 00:10:59.960
<v Speaker 1>Avoid it good advice avoid with Okay, last fundamental strict

230
00:11:00.159 --> 00:11:02.399
<v Speaker 1>mode you strict. Why should we use this?

231
00:11:02.720 --> 00:11:06.000
<v Speaker 2>Strict mode is basically a way to opt into a cleaner, safer,

232
00:11:06.159 --> 00:11:08.919
<v Speaker 2>less error prone version of JavaScript. You put the string

233
00:11:09.480 --> 00:11:11.799
<v Speaker 2>you strict at the very top of a script or

234
00:11:11.840 --> 00:11:14.120
<v Speaker 2>a function, and what does it do. It changes certain things.

235
00:11:14.120 --> 00:11:17.960
<v Speaker 2>It turned some previously silent errors into throne errors. For example,

236
00:11:18.000 --> 00:11:20.879
<v Speaker 2>assigning a value to an undeclared variable throws an error

237
00:11:21.120 --> 00:11:23.440
<v Speaker 2>instead of implicitly creating a global variable.

238
00:11:23.480 --> 00:11:26.000
<v Speaker 1>Ah. That's good. Helps catch typos exactly.

239
00:11:26.519 --> 00:11:30.320
<v Speaker 2>It also prevents or throws errors for certain unsafe actions

240
00:11:30.720 --> 00:11:34.919
<v Speaker 2>like deleting variables or functions. It bans the wis statement.

241
00:11:35.279 --> 00:11:38.679
<v Speaker 2>It makes evil safer. It prevents using reserved words like

242
00:11:38.759 --> 00:11:40.960
<v Speaker 2>evil or arguments as variable names.

243
00:11:41.039 --> 00:11:43.600
<v Speaker 1>So it basically tightens up the rules and catches common

244
00:11:43.639 --> 00:11:44.799
<v Speaker 1>mistakes pretty much.

245
00:11:45.000 --> 00:11:48.159
<v Speaker 2>It helps you write more robust, maintainable code. It's highly

246
00:11:48.200 --> 00:11:50.200
<v Speaker 2>recommended for all modern JavaScript development.

247
00:11:50.200 --> 00:11:53.240
<v Speaker 1>Makes total sense like built in code review. Okay, let's

248
00:11:53.240 --> 00:11:57.240
<v Speaker 1>switch gears to objects in a raise complex data first.

249
00:11:57.519 --> 00:12:02.159
<v Speaker 1>That distinction primitive versus reference value. Why is this so critical?

250
00:12:02.440 --> 00:12:08.120
<v Speaker 2>It fundamentally changes how you work with data. Primitive values, numbers, strings, booleans,

251
00:12:08.120 --> 00:12:10.600
<v Speaker 2>et cetera. Are passed by value. When you assign a

252
00:12:10.600 --> 00:12:13.840
<v Speaker 2>primitive variable to another, you're making a completely separate.

253
00:12:13.480 --> 00:12:15.320
<v Speaker 1>Copy, independent copies, right.

254
00:12:15.519 --> 00:12:18.600
<v Speaker 2>But reference values objects in a raise are passed by reference.

255
00:12:18.960 --> 00:12:21.960
<v Speaker 2>When you assign an object variable to another, both variables

256
00:12:22.039 --> 00:12:24.679
<v Speaker 2>end up pointing to the exact same object in memory.

257
00:12:24.399 --> 00:12:27.960
<v Speaker 1>So changing the object through one variable affects the other absolutely.

258
00:12:28.159 --> 00:12:30.360
<v Speaker 2>If you have OBJ one down a OBJ two dot

259
00:12:30.440 --> 00:12:32.320
<v Speaker 2>day one and then you do OBJ two dot name

260
00:12:32.320 --> 00:12:34.519
<v Speaker 2>aples a b UPJ one dot name will also be b.

261
00:12:35.120 --> 00:12:37.919
<v Speaker 2>They're referencing the same underlying data structure. Understanding this is

262
00:12:37.919 --> 00:12:40.000
<v Speaker 2>crucial for avoiding unexpected side effects.

263
00:12:40.000 --> 00:12:43.679
<v Speaker 1>Definitely okay, So how do we figure out what type

264
00:12:43.720 --> 00:12:46.799
<v Speaker 1>of data we have? Type of seems like the obvious choice,

265
00:12:46.840 --> 00:12:47.759
<v Speaker 1>but it has quirks.

266
00:12:47.840 --> 00:12:51.480
<v Speaker 2>It does type or for works great for primitives number, string,

267
00:12:52.000 --> 00:12:57.360
<v Speaker 2>boolly and undefined symbol big int. It also correctly identifies

268
00:12:57.399 --> 00:12:58.799
<v Speaker 2>functions returning function.

269
00:12:58.919 --> 00:13:00.759
<v Speaker 1>But for objects, and as for.

270
00:13:00.799 --> 00:13:04.000
<v Speaker 2>Most reference types, including regular objects in arrays, type offf

271
00:13:04.080 --> 00:13:07.879
<v Speaker 2>just returns object, and confusingly, type of null also returns object.

272
00:13:08.039 --> 00:13:09.799
<v Speaker 2>That's a long standing historical bug.

273
00:13:10.080 --> 00:13:12.559
<v Speaker 1>So type of isn't always specific enough for objects. What

274
00:13:12.639 --> 00:13:13.360
<v Speaker 1>else can we use?

275
00:13:13.600 --> 00:13:16.440
<v Speaker 2>The instance of operator is often better for checking object types.

276
00:13:16.720 --> 00:13:18.879
<v Speaker 2>You can do my array instance of array or my

277
00:13:19.039 --> 00:13:21.080
<v Speaker 2>date instance of date to see if an object was

278
00:13:21.120 --> 00:13:24.200
<v Speaker 2>created by a specific constructor or inherits from its prototype.

279
00:13:24.240 --> 00:13:27.960
<v Speaker 1>Okay, instance of for more specific object checks now scope.

280
00:13:28.080 --> 00:13:30.639
<v Speaker 1>How does JavaScript know which variable we mean when we

281
00:13:30.759 --> 00:13:33.200
<v Speaker 1>use a name? The scope chain exactly.

282
00:13:33.799 --> 00:13:38.320
<v Speaker 2>Scope determines where variables are accessible. JavaScript uses lexical scope,

283
00:13:38.559 --> 00:13:41.279
<v Speaker 2>meaning scope is defined by where the code is physically written.

284
00:13:41.840 --> 00:13:44.519
<v Speaker 2>When you use a variable, the engine first looks in

285
00:13:44.559 --> 00:13:47.639
<v Speaker 2>the current innermost scope, and if it's not there, looks

286
00:13:47.639 --> 00:13:49.559
<v Speaker 2>in the next scope outwards, then the next, and so

287
00:13:49.639 --> 00:13:53.440
<v Speaker 2>on up the chain until it hits the global scope.

288
00:13:53.480 --> 00:13:56.440
<v Speaker 2>This sequence of scopes is the.

289
00:13:56.360 --> 00:13:59.360
<v Speaker 3>Scope chain, like nested boxes pretty much.

290
00:13:59.559 --> 00:14:01.559
<v Speaker 2>If it which is the global scope and still doesn't

291
00:14:01.559 --> 00:14:04.600
<v Speaker 2>find the variable, you get a reference error in strict mode. Anyway,

292
00:14:05.080 --> 00:14:07.759
<v Speaker 2>looking up globals can be slightly slower than locals because

293
00:14:07.799 --> 00:14:11.039
<v Speaker 2>the chain might be longer, but engines optimize this well.

294
00:14:11.240 --> 00:14:15.480
<v Speaker 1>Okay. And memory management, JavaScript cleans up after itself with

295
00:14:15.559 --> 00:14:17.039
<v Speaker 1>garbage collection. How does that work?

296
00:14:17.120 --> 00:14:21.480
<v Speaker 2>Yes? JavaScript has automatic garbage collection PC. The engine tracks

297
00:14:21.480 --> 00:14:24.759
<v Speaker 2>which objects are still reachable, meaning they can somehow be accessed,

298
00:14:24.960 --> 00:14:27.519
<v Speaker 2>starting from the root objects like the global.

299
00:14:27.200 --> 00:14:30.039
<v Speaker 1>Window object, so it traces all the references kind of.

300
00:14:30.360 --> 00:14:33.919
<v Speaker 2>The most common algorithm is mark and sweep. The GC

301
00:14:34.000 --> 00:14:36.960
<v Speaker 2>starts at the roots, marks all reachable objects, and then

302
00:14:37.039 --> 00:14:41.039
<v Speaker 2>sweeps through memory reclaiming the memory used by any object

303
00:14:41.080 --> 00:14:42.080
<v Speaker 2>that wasn't marked.

304
00:14:42.200 --> 00:14:44.840
<v Speaker 1>So if nothing points to an object anymore, it gets

305
00:14:44.840 --> 00:14:45.399
<v Speaker 1>swept up.

306
00:14:45.600 --> 00:14:50.039
<v Speaker 2>Essentially, Yes, it's automatic, but not fool proof. You can

307
00:14:50.080 --> 00:14:53.279
<v Speaker 2>still create memory leaks if you unintentionally keep references to

308
00:14:53.320 --> 00:14:56.240
<v Speaker 2>objects you no longer need. And the timing of GC

309
00:14:56.440 --> 00:14:59.279
<v Speaker 2>is nondeterministic. You don't control exactly when it runs.

310
00:15:00.000 --> 00:15:02.360
<v Speaker 1>I know it's mostly handled, but leaks are still possible.

311
00:15:02.799 --> 00:15:05.759
<v Speaker 1>All right, let's look at specific reference types. The basic object.

312
00:15:05.799 --> 00:15:07.840
<v Speaker 1>It's more than just key value pairs, isn't it.

313
00:15:07.879 --> 00:15:11.279
<v Speaker 2>Oh yeah. Object is the foundation for almost everything complex

314
00:15:11.279 --> 00:15:14.919
<v Speaker 2>in JavaScript. It's a dynamic collection of properties where keys

315
00:15:14.960 --> 00:15:17.799
<v Speaker 2>are usually strings or symbols, and values can be anything.

316
00:15:17.919 --> 00:15:20.879
<v Speaker 2>We usually create them with object literals. It's the basis

317
00:15:20.879 --> 00:15:23.879
<v Speaker 2>for prototype based inheritance, which is core to JS.

318
00:15:24.039 --> 00:15:27.159
<v Speaker 1>The cornerstone, okay, an array. It's like a list, but

319
00:15:27.360 --> 00:15:29.320
<v Speaker 1>more flexible than in some languages.

320
00:15:29.600 --> 00:15:33.600
<v Speaker 2>Definitely. JavaScript arrays are ordered lists, but they're dynamic. They

321
00:15:33.600 --> 00:15:36.320
<v Speaker 2>can grow and shrink, and importantly, they can hold elements

322
00:15:36.320 --> 00:15:38.919
<v Speaker 2>of any data type mixed together. A single ray could

323
00:15:38.960 --> 00:15:41.679
<v Speaker 2>have numbers, strings, objects, even other.

324
00:15:41.639 --> 00:15:43.080
<v Speaker 3>Arrays very flexible.

325
00:15:43.159 --> 00:15:45.399
<v Speaker 1>How do we make arrays. Literals are common.

326
00:15:45.600 --> 00:15:48.000
<v Speaker 2>Literals are the most common and usually the best way.

327
00:15:48.120 --> 00:15:49.919
<v Speaker 2>You can also use new array, but it has some

328
00:15:49.960 --> 00:15:53.240
<v Speaker 2>weird behavior if you pass just one number argument. A

329
00:15:53.360 --> 00:15:56.279
<v Speaker 2>ray out from is super useful for converting array like

330
00:15:56.360 --> 00:15:59.879
<v Speaker 2>things like dom modalists or the argument's object or iter

331
00:16:00.360 --> 00:16:02.559
<v Speaker 2>like sets or maps into real arrays.

332
00:16:02.679 --> 00:16:05.440
<v Speaker 1>Array dot from some sandy and array dot from.

333
00:16:05.360 --> 00:16:08.080
<v Speaker 2>Array does creates a new array with whatever arguments you

334
00:16:08.120 --> 00:16:10.000
<v Speaker 2>pass it. A ray dot one two three gives one

335
00:16:10.000 --> 00:16:12.039
<v Speaker 2>two three, and a ray of seven gives seven. It

336
00:16:12.080 --> 00:16:14.480
<v Speaker 2>avoids the new array seven confusion, which creates an mpty

337
00:16:14.519 --> 00:16:15.399
<v Speaker 2>array of length seven.

338
00:16:15.519 --> 00:16:20.879
<v Speaker 1>Got it now changing array contents, dot fil sort, splice,

339
00:16:21.080 --> 00:16:21.720
<v Speaker 1>What do these do?

340
00:16:21.799 --> 00:16:23.799
<v Speaker 2>Phil Let's you set all or part of an array

341
00:16:23.799 --> 00:16:27.799
<v Speaker 2>to a static value. Useful for initialization. Sort sorts the

342
00:16:27.879 --> 00:16:31.559
<v Speaker 2>array in place than gotcha. By default, it sorts lexicographically

343
00:16:31.639 --> 00:16:32.639
<v Speaker 2>like stringths.

344
00:16:32.240 --> 00:16:35.080
<v Speaker 1>So one ten two would sort to one ten two exactly.

345
00:16:35.200 --> 00:16:38.399
<v Speaker 2>For numeric sorting, you must provide a comparison function like

346
00:16:38.440 --> 00:16:41.399
<v Speaker 2>ab equal ab for ascending order.

347
00:16:41.320 --> 00:16:44.039
<v Speaker 1>Right always provide the compare function for numbers, and splice.

348
00:16:44.120 --> 00:16:46.639
<v Speaker 2>Splice is the Swiss army knife. Let's remove elements in

349
00:16:46.679 --> 00:16:49.799
<v Speaker 2>some elements or replace elements all of a specific index,

350
00:16:49.840 --> 00:16:53.320
<v Speaker 2>modifying the original array directly. It's very powerful. Splice in

351
00:16:53.480 --> 00:16:55.039
<v Speaker 2>x lead count outum one item.

352
00:16:54.919 --> 00:16:58.399
<v Speaker 1>Two okay, modifies in place. What about finding things? Index

353
00:16:58.440 --> 00:17:00.200
<v Speaker 1>of last and x xen inclusion.

354
00:17:00.000 --> 00:17:02.159
<v Speaker 2>The first index of an item searching forwards last index

355
00:17:02.240 --> 00:17:05.079
<v Speaker 2>yeah finds the last index searching backwards. Both return to

356
00:17:05.240 --> 00:17:07.759
<v Speaker 2>nus one if not found, and both use strict equality

357
00:17:07.839 --> 00:17:10.400
<v Speaker 2>and include just returns true or if false if the item

358
00:17:10.440 --> 00:17:12.880
<v Speaker 2>exists in the array. Simpler if you don't need the index.

359
00:17:12.920 --> 00:17:15.839
<v Speaker 2>It also uses strict equality index of and last index.

360
00:17:15.920 --> 00:17:18.559
<v Speaker 2>Oves can take an optional second argument for the starting

361
00:17:18.599 --> 00:17:19.240
<v Speaker 2>search position.

362
00:17:19.680 --> 00:17:24.240
<v Speaker 1>Use includes for existence, check indexoflast, index of if you

363
00:17:24.279 --> 00:17:27.200
<v Speaker 1>need the position. And reduce sounds like it boils an

364
00:17:27.240 --> 00:17:27.720
<v Speaker 1>array down.

365
00:17:28.000 --> 00:17:31.279
<v Speaker 2>It does. Reduce iterates through an array applying a function

366
00:17:31.279 --> 00:17:34.240
<v Speaker 2>you provide to accumulate a single result. The function gets

367
00:17:34.279 --> 00:17:37.480
<v Speaker 2>the accumulator, the current value, the index, and the array itself.

368
00:17:37.880 --> 00:17:40.440
<v Speaker 2>You can some numbers, build an object, flatten an array

369
00:17:41.240 --> 00:17:45.039
<v Speaker 2>really versatile. You usually provide an initial value for the accumulator.

370
00:17:45.200 --> 00:17:49.000
<v Speaker 1>Powerful stuff, okay. Type dearrays in eight array float thirty

371
00:17:49.079 --> 00:17:53.519
<v Speaker 1>two array. These sound specialized? Why use them over regular arrays.

372
00:17:53.519 --> 00:17:57.759
<v Speaker 2>Performance, mainly when dealing with raw binary data. Regular rays

373
00:17:57.799 --> 00:18:01.519
<v Speaker 2>are super flexible, but that flexibility has overhead. Type raise

374
00:18:01.559 --> 00:18:03.920
<v Speaker 2>give you a direct fixed length view onto a chunk

375
00:18:03.920 --> 00:18:07.079
<v Speaker 2>of binary memory an array buffer, where each element is

376
00:18:07.119 --> 00:18:10.759
<v Speaker 2>known to be a specific numeric type like eight bit unsigned, editger,

377
00:18:10.880 --> 00:18:12.200
<v Speaker 2>thirty two bit float, et cetera.

378
00:18:12.519 --> 00:18:15.880
<v Speaker 1>So for things like graphics or processing audio data.

379
00:18:15.559 --> 00:18:19.960
<v Speaker 2>Exactly WebGL web audio API manipulating file data read into

380
00:18:20.000 --> 00:18:22.960
<v Speaker 2>an array buffer. They share many methods with regular arrays,

381
00:18:23.039 --> 00:18:25.799
<v Speaker 2>map filter, etc. But they operate within the constraints of

382
00:18:25.799 --> 00:18:28.240
<v Speaker 2>their type and fixed length. They also have methods like

383
00:18:28.359 --> 00:18:31.960
<v Speaker 2>set for efficiently copying data in and subaray to create

384
00:18:32.000 --> 00:18:33.839
<v Speaker 2>a new typed to array view over a portion of

385
00:18:33.839 --> 00:18:34.960
<v Speaker 2>the same buffer.

386
00:18:34.720 --> 00:18:38.920
<v Speaker 1>Efficient binary data handling and data view. How's that different?

387
00:18:39.240 --> 00:18:41.880
<v Speaker 2>Data View also works on an array buffer, but it's

388
00:18:41.920 --> 00:18:44.799
<v Speaker 2>even lower level. Instead of viewing the whole buffer as

389
00:18:44.839 --> 00:18:47.400
<v Speaker 2>one type, data view lets you read and write different

390
00:18:47.480 --> 00:18:50.880
<v Speaker 2>numeric types at any byte offset within the buffer.

391
00:18:50.680 --> 00:18:52.599
<v Speaker 1>So you could read an eight bit in then a

392
00:18:52.720 --> 00:18:54.599
<v Speaker 1>sixteen bit float from the same.

393
00:18:54.400 --> 00:18:57.759
<v Speaker 2>Buffer precisely, and crucially, data view lets you control the

394
00:18:57.920 --> 00:19:01.559
<v Speaker 2>endianness byte order big indian or little endian for multi

395
00:19:01.559 --> 00:19:04.640
<v Speaker 2>byte types. This is essential when you're working with specific

396
00:19:04.680 --> 00:19:08.799
<v Speaker 2>file formats or network protocols that dictate a particular byte order.

397
00:19:08.960 --> 00:19:12.880
<v Speaker 1>So typed arrays for uniform numeric arrays. Data view for

398
00:19:13.000 --> 00:19:17.200
<v Speaker 1>fine grained multi type endingess controlled access to binary data.

399
00:19:17.240 --> 00:19:18.000
<v Speaker 2>That's a great summary.

400
00:19:18.079 --> 00:19:21.000
<v Speaker 1>Okay, let's talk collections, map and set. How are they

401
00:19:21.000 --> 00:19:22.920
<v Speaker 1>different from plain objects and arrays.

402
00:19:23.039 --> 00:19:25.599
<v Speaker 2>Map is like an object for key value pairs, but

403
00:19:25.680 --> 00:19:28.680
<v Speaker 2>with key differences. Keys in a map can be any

404
00:19:28.759 --> 00:19:31.279
<v Speaker 2>data type, not just strings or symbols. You can use

405
00:19:31.319 --> 00:19:33.759
<v Speaker 2>an object or even a function as a key. Also,

406
00:19:33.880 --> 00:19:36.000
<v Speaker 2>map remembers the original insertion order.

407
00:19:35.839 --> 00:19:38.400
<v Speaker 1>Of keys any data type as a key and ordered

408
00:19:38.799 --> 00:19:40.039
<v Speaker 1>useful and set.

409
00:19:40.279 --> 00:19:43.400
<v Speaker 2>Set is a collection of unique values you add items,

410
00:19:43.640 --> 00:19:47.359
<v Speaker 2>and duplicates are automatically ignored. Like MAP, it also remembers

411
00:19:47.400 --> 00:19:50.839
<v Speaker 2>insertion order. Great for quickly removing duplicates from an array

412
00:19:51.160 --> 00:19:53.240
<v Speaker 2>or just storing a list where uniqueness matters.

413
00:19:53.359 --> 00:19:57.880
<v Speaker 1>Set for uniqueness map for flexible keys. What about weak set?

414
00:19:57.920 --> 00:19:59.240
<v Speaker 1>What's weak about it?

415
00:19:59.440 --> 00:20:02.079
<v Speaker 2>Weekset is it's like set, but it only holds objects,

416
00:20:02.160 --> 00:20:05.039
<v Speaker 2>and it holds them weekly. This means if an object

417
00:20:05.079 --> 00:20:07.319
<v Speaker 2>is only referenced by the weakset and nowhere else in

418
00:20:07.359 --> 00:20:10.000
<v Speaker 2>your code. The garbage collector is free to remove it.

419
00:20:10.039 --> 00:20:13.079
<v Speaker 1>Ah, so it doesn't prevent garbage collection. Why is that useful?

420
00:20:13.319 --> 00:20:16.880
<v Speaker 2>It's great for associating metadata with objects without preventing those

421
00:20:16.880 --> 00:20:19.720
<v Speaker 2>objects from being cleaned up if they're removed from say

422
00:20:20.000 --> 00:20:22.839
<v Speaker 2>the DOM. If you remove a DOM element and it

423
00:20:22.880 --> 00:20:25.119
<v Speaker 2>was in the week set, the weekset reference won't keep

424
00:20:25.160 --> 00:20:28.200
<v Speaker 2>it lingering in memory because items can disappear. You can't

425
00:20:28.240 --> 00:20:29.599
<v Speaker 2>iterate over a week set.

426
00:20:29.960 --> 00:20:34.839
<v Speaker 1>Smart for managing metadata on potentially transient objects. Okay, iterating

427
00:20:34.839 --> 00:20:38.599
<v Speaker 1>over these collections in arrays and strings. The iteration protocols.

428
00:20:38.680 --> 00:20:40.960
<v Speaker 1>What's the deal with symbol dot iterator?

429
00:20:41.359 --> 00:20:44.359
<v Speaker 2>Right? For an object to be considered iterable, meaning you

430
00:20:44.400 --> 00:20:46.759
<v Speaker 2>can use it with for out of loops or spread syntax,

431
00:20:47.160 --> 00:20:49.720
<v Speaker 2>it needs to have a method whose key is the

432
00:20:49.720 --> 00:20:52.680
<v Speaker 2>well known symbol symbol dot iterator.

433
00:20:52.559 --> 00:20:53.759
<v Speaker 1>And what does that method do?

434
00:20:54.200 --> 00:20:57.880
<v Speaker 2>That method, when called, must return an iterator object. The

435
00:20:57.960 --> 00:21:00.880
<v Speaker 2>iterator object, in turn, must have an next method.

436
00:21:00.920 --> 00:21:02.640
<v Speaker 1>And next gives you the value.

437
00:21:02.839 --> 00:21:06.359
<v Speaker 2>Calling next returns an object with two properties value the

438
00:21:06.400 --> 00:21:09.200
<v Speaker 2>next value in the sequence and done a boollion that's

439
00:21:09.240 --> 00:21:11.880
<v Speaker 2>false until the iteration is complete, then it becomes true.

440
00:21:12.079 --> 00:21:15.960
<v Speaker 1>So iterable means has symbol dot iterator, which gives an

441
00:21:15.960 --> 00:21:18.160
<v Speaker 1>iterator which has naxt got it.

442
00:21:18.200 --> 00:21:19.279
<v Speaker 2>That's the contract and for.

443
00:21:19.319 --> 00:21:21.160
<v Speaker 1>Data Bouve just handles all that automatically.

444
00:21:21.319 --> 00:21:24.160
<v Speaker 2>Yep fata b loops are designed specifically to work with

445
00:21:24.200 --> 00:21:27.680
<v Speaker 2>this protocol. It calls symbol dot iterator, gets the iterator,

446
00:21:27.799 --> 00:21:30.799
<v Speaker 2>and keeps calling next until done is true, give you

447
00:21:30.839 --> 00:21:34.000
<v Speaker 2>the value at each step. Works on a raise strings, map, sets,

448
00:21:34.039 --> 00:21:35.279
<v Speaker 2>no lists anything.

449
00:21:35.359 --> 00:21:38.240
<v Speaker 1>Iterable much nicer than old four loops with index counters.

450
00:21:38.240 --> 00:21:43.599
<v Speaker 1>Sometimes now generators dot function How do they fit into iteration?

451
00:21:44.039 --> 00:21:46.880
<v Speaker 2>Generators are a special kind of function defined with function.

452
00:21:47.400 --> 00:21:49.680
<v Speaker 2>When you call a generator function, it doesn't run the

453
00:21:49.680 --> 00:21:53.359
<v Speaker 2>code immediately. Instead, it returns a generator object, which is

454
00:21:53.400 --> 00:21:54.039
<v Speaker 2>an iterator.

455
00:21:54.319 --> 00:21:56.960
<v Speaker 1>So calling it gives you the iterator directly.

456
00:21:57.079 --> 00:22:00.000
<v Speaker 2>Yes. Inside the generator function, you use the yield keyword.

457
00:22:00.000 --> 00:22:04.119
<v Speaker 2>Word yield pauses the function's execution and sends a value

458
00:22:04.119 --> 00:22:07.599
<v Speaker 2>out that becomes the value in the value done object.

459
00:22:07.359 --> 00:22:09.160
<v Speaker 3>From next pauses the function Yeah.

460
00:22:09.559 --> 00:22:12.039
<v Speaker 2>The next time you call next on the generator object,

461
00:22:12.279 --> 00:22:14.720
<v Speaker 2>the function resumes exactly where it left off right after

462
00:22:14.799 --> 00:22:17.480
<v Speaker 2>the yield and continues until it hits the next yield

463
00:22:17.640 --> 00:22:18.160
<v Speaker 2>or the end.

464
00:22:18.160 --> 00:22:21.440
<v Speaker 1>Of the function whoa functions that pause and resume.

465
00:22:21.720 --> 00:22:25.240
<v Speaker 2>It's powerful makes writing complex iterators much easier. You can

466
00:22:25.240 --> 00:22:29.319
<v Speaker 2>also use yield to delegate iteration to another iterable or generator.

467
00:22:29.480 --> 00:22:33.480
<v Speaker 1>Fascinating and async iterators a sync function and for a

468
00:22:33.480 --> 00:22:36.400
<v Speaker 1>weight dot f. This is for asynchronous sequences exactly.

469
00:22:36.759 --> 00:22:40.880
<v Speaker 2>ACNC iteration protocols handle sequences where the values arrive asynchronously,

470
00:22:40.960 --> 00:22:44.519
<v Speaker 2>like data streaming over a network, and ACNC literable has

471
00:22:44.839 --> 00:22:48.640
<v Speaker 2>symbol dot ACNC iterator, which returns an ACNC iterator.

472
00:22:48.240 --> 00:22:49.319
<v Speaker 1>And its next method.

473
00:22:49.480 --> 00:22:52.759
<v Speaker 2>Its next method returns a promise that resolves to the

474
00:22:52.839 --> 00:22:54.200
<v Speaker 2>value downe object ah.

475
00:22:54.319 --> 00:22:56.680
<v Speaker 1>So next is async itself.

476
00:22:56.359 --> 00:22:58.400
<v Speaker 2>Right, and the four weight of loop is designed to

477
00:22:58.440 --> 00:23:02.039
<v Speaker 2>work with these. It weighs asynchronously for the promise from

478
00:23:02.079 --> 00:23:05.960
<v Speaker 2>next to resolve before each iteration. Perfect for handling streams

479
00:23:05.960 --> 00:23:08.680
<v Speaker 2>of data like chunks from a fetch response or server

480
00:23:08.759 --> 00:23:09.359
<v Speaker 2>send events.

481
00:23:10.000 --> 00:23:10.480
<v Speaker 3>Very cool.

482
00:23:10.640 --> 00:23:17.119
<v Speaker 1>Okay, let's dive deeper into objects. Property attributes, configurable, innumerable, writable.

483
00:23:18.000 --> 00:23:19.319
<v Speaker 1>What are these internal things?

484
00:23:19.640 --> 00:23:23.039
<v Speaker 2>Every object property has these internal attributes to control its behavior.

485
00:23:23.400 --> 00:23:26.200
<v Speaker 2>Configurable means can the property be deleted or can its

486
00:23:26.240 --> 00:23:29.559
<v Speaker 2>attributes be changed later? Innumerable means does it show up

487
00:23:29.559 --> 00:23:32.960
<v Speaker 2>in four lot loombs, ritable means can its value be changed?

488
00:23:33.000 --> 00:23:34.720
<v Speaker 2>And value holds the actual value.

489
00:23:34.759 --> 00:23:37.319
<v Speaker 1>So they define the meta behavior of the property exactly.

490
00:23:37.480 --> 00:23:41.119
<v Speaker 2>They're also get and set attributes for accessor properties getters

491
00:23:41.119 --> 00:23:42.880
<v Speaker 2>and setters instead of value.

492
00:23:42.640 --> 00:23:45.720
<v Speaker 1>And ritable, and we control these using object dot define property.

493
00:23:46.039 --> 00:23:50.240
<v Speaker 2>Yes, object dot define property lets you define a new

494
00:23:50.279 --> 00:23:53.960
<v Speaker 2>property or modify an existing one and explicitly set these

495
00:23:54.039 --> 00:23:58.240
<v Speaker 2>attribute values like innumerable dot false or ritable dot false.

496
00:23:58.960 --> 00:24:01.680
<v Speaker 2>You can also define getter and setter functions using this

497
00:24:02.240 --> 00:24:04.759
<v Speaker 2>object out defined properties lets you do it for multiple

498
00:24:04.799 --> 00:24:05.640
<v Speaker 2>properties at once.

499
00:24:05.759 --> 00:24:08.720
<v Speaker 1>Gives you fine grain control. Now, object literals have some

500
00:24:08.799 --> 00:24:10.480
<v Speaker 1>nice shorthands these days, right they do.

501
00:24:10.599 --> 00:24:12.440
<v Speaker 2>If you have variable X and you want an object

502
00:24:12.480 --> 00:24:15.319
<v Speaker 2>property x with that variable's value, you can just write

503
00:24:15.559 --> 00:24:16.599
<v Speaker 2>x instead of xx.

504
00:24:16.799 --> 00:24:18.359
<v Speaker 1>Nice. And for methods you can.

505
00:24:18.359 --> 00:24:21.839
<v Speaker 2>Write my methods my method dot function cleaner syntax.

506
00:24:21.400 --> 00:24:22.640
<v Speaker 1>And computed property keys.

507
00:24:22.720 --> 00:24:25.480
<v Speaker 2>Yeah, you can use square brackets inside an object literal

508
00:24:25.559 --> 00:24:27.880
<v Speaker 2>to use the result of an expression as a property

509
00:24:27.920 --> 00:24:31.119
<v Speaker 2>key like prefix plus id. Very dynamic.

510
00:24:31.279 --> 00:24:35.000
<v Speaker 1>These shorthands definitely make object creation less verbose. What about

511
00:24:35.039 --> 00:24:37.599
<v Speaker 1>combining objects object dot A sign. How does it work?

512
00:24:37.720 --> 00:24:41.799
<v Speaker 2>Object out a sign target dot sources copies all innumerable

513
00:24:41.839 --> 00:24:44.559
<v Speaker 2>own properties from the source objects into the target object.

514
00:24:44.880 --> 00:24:47.119
<v Speaker 2>It modifies the target directly and returns.

515
00:24:46.799 --> 00:24:49.400
<v Speaker 1>It copies properties. Is it a deep copy?

516
00:24:49.759 --> 00:24:53.119
<v Speaker 2>No. Crucially, it's a shallow copy. If a property value

517
00:24:53.160 --> 00:24:56.160
<v Speaker 2>is an object or array, only the references copy, not

518
00:24:56.240 --> 00:24:59.960
<v Speaker 2>the nested structure itself. Both the target and source will

519
00:25:00.039 --> 00:25:01.440
<v Speaker 2>point to the same nested object.

520
00:25:01.599 --> 00:25:05.200
<v Speaker 1>Okay, shall I copy important limitation? How does it handle

521
00:25:05.240 --> 00:25:06.039
<v Speaker 1>getter setters?

522
00:25:06.480 --> 00:25:09.799
<v Speaker 2>It invokes getters on the source and copies the resulting

523
00:25:09.880 --> 00:25:12.720
<v Speaker 2>value to the target. It doesn't copy the getter function itself.

524
00:25:13.039 --> 00:25:14.000
<v Speaker 2>Setters aren't copied.

525
00:25:14.160 --> 00:25:17.960
<v Speaker 1>Got it useful for emerging simple objects or applying mix ins?

526
00:25:18.400 --> 00:25:21.480
<v Speaker 1>What about getting values out of objects? Destructuring?

527
00:25:21.759 --> 00:25:24.960
<v Speaker 2>Object destructuring is fantastic. It lets you unpack properties from

528
00:25:24.960 --> 00:25:28.319
<v Speaker 2>an object directly into variables like const name age user.

529
00:25:28.200 --> 00:25:31.039
<v Speaker 1>Much cleaner than constname user dot name constant age user

530
00:25:31.079 --> 00:25:32.319
<v Speaker 1>dot age way cleaner.

531
00:25:32.599 --> 00:25:37.279
<v Speaker 2>You can also rename variables comments, provide default values, constme measures,

532
00:25:37.599 --> 00:25:40.400
<v Speaker 2>and use the rest syntax to collect remaining properties into

533
00:25:40.440 --> 00:25:43.279
<v Speaker 2>a new object. Constant aid rest data.

534
00:25:43.279 --> 00:25:47.000
<v Speaker 1>Super useful for working with API responses or config and

535
00:25:47.039 --> 00:25:50.000
<v Speaker 1>the spread operator also works inside object literals.

536
00:25:50.319 --> 00:25:53.160
<v Speaker 2>Yes, similar to object dot assign it lets you spread

537
00:25:53.200 --> 00:25:56.279
<v Speaker 2>the properties of an existing object into a new object

538
00:25:56.599 --> 00:26:01.960
<v Speaker 2>literal constant new user u uzer age thirty one is

539
00:26:02.000 --> 00:26:07.799
<v Speaker 2>admin false. Also a shallow copy. Great for creating modified

540
00:26:07.799 --> 00:26:09.640
<v Speaker 2>copies of objects nondestructively.

541
00:26:09.880 --> 00:26:12.640
<v Speaker 1>Okay, spread for creating new objects based on old ones.

542
00:26:12.799 --> 00:26:16.200
<v Speaker 1>Now the tricky this keyword. Its value depends on how

543
00:26:16.240 --> 00:26:16.880
<v Speaker 1>a function.

544
00:26:16.680 --> 00:26:19.680
<v Speaker 2>Is called right, hugely depends on the call site. In

545
00:26:19.759 --> 00:26:23.079
<v Speaker 2>a regular function called directly, not as an object method,

546
00:26:23.119 --> 00:26:26.119
<v Speaker 2>this is the global object window and browsers in non

547
00:26:26.119 --> 00:26:28.440
<v Speaker 2>strict mode and undefined as strict mode.

548
00:26:28.559 --> 00:26:30.960
<v Speaker 1>Okay, what about when it's a method like an object

549
00:26:31.000 --> 00:26:32.000
<v Speaker 1>dot do something.

550
00:26:31.720 --> 00:26:34.319
<v Speaker 2>Then this inside do something refers to object the object

551
00:26:34.319 --> 00:26:35.200
<v Speaker 2>the method was called on.

552
00:26:35.319 --> 00:26:37.440
<v Speaker 1>Makes sense, and we can explicitly set this yep.

553
00:26:37.480 --> 00:26:40.079
<v Speaker 2>Using function dot call this rg R one, function dot

554
00:26:40.079 --> 00:26:43.119
<v Speaker 2>apply this ars array, or function dot bind this arg

555
00:26:43.359 --> 00:26:46.839
<v Speaker 2>which returns a new function permanently bound to that this value.

556
00:26:46.559 --> 00:26:48.279
<v Speaker 1>And ero functions they're different.

557
00:26:48.319 --> 00:26:52.200
<v Speaker 2>Completely different regarding this erofunctions don't have their own this.

558
00:26:52.519 --> 00:26:56.599
<v Speaker 2>They lexically capture this value from their surrounding scope at

559
00:26:56.599 --> 00:26:59.519
<v Speaker 2>the time they are defined. This solves many old problems,

560
00:26:59.680 --> 00:27:02.480
<v Speaker 2>especially with callbacks inside methods that lexical.

561
00:27:02.559 --> 00:27:05.519
<v Speaker 1>This in aerow functions is a key feature. Okay, let's

562
00:27:05.519 --> 00:27:10.640
<v Speaker 1>talk inheritance prototypes. This is JavaScript's core inheritance model, right,

563
00:27:11.079 --> 00:27:12.799
<v Speaker 1>not classes, initially.

564
00:27:12.440 --> 00:27:16.720
<v Speaker 2>Correct, JavaScript uses prototype based inheritance. Every function is a

565
00:27:16.720 --> 00:27:19.519
<v Speaker 2>prototype property, which is an object. When you use a

566
00:27:19.519 --> 00:27:23.279
<v Speaker 2>function as a constructor with new the object created inherence

567
00:27:23.359 --> 00:27:26.000
<v Speaker 2>from the constructor's prototype, object inherits.

568
00:27:26.039 --> 00:27:26.720
<v Speaker 1>How does that work?

569
00:27:26.799 --> 00:27:30.119
<v Speaker 2>Every object has an internal link, often accessible via proto,

570
00:27:30.240 --> 00:27:33.480
<v Speaker 2>though object dot get prototype of is the standard way

571
00:27:33.519 --> 00:27:36.119
<v Speaker 2>to read it to its prototype. When you try to

572
00:27:36.160 --> 00:27:38.680
<v Speaker 2>access a property on an object, if the object doesn't

573
00:27:38.680 --> 00:27:41.839
<v Speaker 2>have it directly, JavaScript looks at its prototype. If the

574
00:27:41.839 --> 00:27:44.119
<v Speaker 2>prototype doesn't have it, it looks at its prototype, and so

575
00:27:44.200 --> 00:27:45.240
<v Speaker 2>on up the chain.

576
00:27:45.119 --> 00:27:47.720
<v Speaker 1>The prototype chain, so properties are looked up along this

577
00:27:47.839 --> 00:27:48.920
<v Speaker 1>chain exactly.

578
00:27:49.000 --> 00:27:53.079
<v Speaker 2>That's how inheritance works. Methods defined on a constructor's prototype

579
00:27:53.279 --> 00:27:56.759
<v Speaker 2>are shared by all instances created from that constructor. You

580
00:27:56.799 --> 00:28:00.200
<v Speaker 2>can use object dot is prototype of another object to

581
00:28:00.279 --> 00:28:01.519
<v Speaker 2>check the chain relationship.

582
00:28:01.599 --> 00:28:04.400
<v Speaker 1>Okay, Prototypes are the real mechanism. So what about ES

583
00:28:04.480 --> 00:28:07.839
<v Speaker 1>six class syntax? Is that just sugar on top.

584
00:28:08.039 --> 00:28:11.400
<v Speaker 2>Pretty much class provides a cleaner, more familiar syntax for

585
00:28:11.480 --> 00:28:15.359
<v Speaker 2>setting up constructor functions and their prototypes. The constructor method

586
00:28:15.480 --> 00:28:19.839
<v Speaker 2>inside a class defines the constructor function. Other methods defined

587
00:28:19.880 --> 00:28:23.200
<v Speaker 2>in the class body automatically get added to the class's prototype.

588
00:28:23.319 --> 00:28:26.880
<v Speaker 1>So it makes prototype inheritance look more like classical inheritance.

589
00:28:27.200 --> 00:28:31.319
<v Speaker 2>Kind of yes, it simplifies the syntax. Class also introduces

590
00:28:31.319 --> 00:28:35.039
<v Speaker 2>features like static members belonging to the class itself, not instances,

591
00:28:35.640 --> 00:28:39.119
<v Speaker 2>and more recently, private members using the hashtag prefix for

592
00:28:39.160 --> 00:28:43.079
<v Speaker 2>true encapsulation. But underneath it's still leveraging the prototype chain.

593
00:28:43.160 --> 00:28:47.559
<v Speaker 1>Good to know classes mostly syntax over the existing prototype system. Okay,

594
00:28:47.640 --> 00:28:50.799
<v Speaker 1>let's focus specifically on functions. Now different ways to define

595
00:28:50.799 --> 00:28:53.279
<v Speaker 1>them declarations, expressions, arrows right.

596
00:28:53.519 --> 00:28:57.319
<v Speaker 2>Function declarations look like function my function. These are fully hoisted.

597
00:28:57.440 --> 00:28:59.240
<v Speaker 2>You can call them before they appear in the.

598
00:28:59.240 --> 00:29:01.119
<v Speaker 1>Code hoisted okay, and expressions.

599
00:29:01.119 --> 00:29:03.599
<v Speaker 2>Function expressions assign a function to a variable like co

600
00:29:04.000 --> 00:29:07.599
<v Speaker 2>hocal function or constant my aerowfunk. With these, only the

601
00:29:07.680 --> 00:29:11.519
<v Speaker 2>variable declaration constant my funk is hoisted, not the function

602
00:29:11.599 --> 00:29:14.000
<v Speaker 2>assignment itself. You can't call them before the line where

603
00:29:14.039 --> 00:29:15.160
<v Speaker 2>they're assigned.

604
00:29:14.839 --> 00:29:19.759
<v Speaker 1>So declarations are fully hoisted expressions including arrows are not correct.

605
00:29:19.359 --> 00:29:22.240
<v Speaker 2>And aero functions have that concise syntax in the lexical

606
00:29:22.319 --> 00:29:25.880
<v Speaker 2>this binding we talked about. There's also the function constructor

607
00:29:26.480 --> 00:29:29.759
<v Speaker 2>new function ab return of plus b, but it's generally discouraged.

608
00:29:29.799 --> 00:29:33.200
<v Speaker 2>Like evil, it executes code from strings, which is slow

609
00:29:33.279 --> 00:29:34.480
<v Speaker 2>and potentially insecure.

610
00:29:34.680 --> 00:29:39.400
<v Speaker 1>Stick to declarations, expressions and arrows. Then, what about handling

611
00:29:39.599 --> 00:29:42.279
<v Speaker 1>arguments rest parameters.

612
00:29:41.680 --> 00:29:46.000
<v Speaker 2>Rest parameters dot orgs let you gather an indefinite number

613
00:29:46.000 --> 00:29:49.559
<v Speaker 2>of trailing arguments passed to a function into a single

614
00:29:49.880 --> 00:29:53.640
<v Speaker 2>real array named arcs, much better than the old arguments.

615
00:29:53.279 --> 00:29:56.119
<v Speaker 1>Object and spread syntax in function calls.

616
00:29:56.039 --> 00:29:59.240
<v Speaker 2>That does the opposite. It takes an iterable like an

617
00:29:59.319 --> 00:30:03.400
<v Speaker 2>array and expands it into individual arguments. When calling a

618
00:30:03.440 --> 00:30:06.920
<v Speaker 2>function my function dot my array.

619
00:30:07.000 --> 00:30:10.480
<v Speaker 1>So rest collects arguments into an array. Spread expands an

620
00:30:10.559 --> 00:30:13.480
<v Speaker 1>array into arguments. Got it and default parameter values.

621
00:30:13.680 --> 00:30:17.160
<v Speaker 2>Yeah, you can set defaults directly in the signature function creed.

622
00:30:17.599 --> 00:30:20.720
<v Speaker 2>If the argument isn't provided or is undefined, the default

623
00:30:20.799 --> 00:30:22.799
<v Speaker 2>is used. Makes functions more robust.

624
00:30:22.920 --> 00:30:25.680
<v Speaker 1>We covered hoisting already. How about functions as values first

625
00:30:25.680 --> 00:30:26.599
<v Speaker 1>class functions?

626
00:30:26.680 --> 00:30:28.960
<v Speaker 2>It just means functions in JavaScript are treated like any

627
00:30:28.960 --> 00:30:31.799
<v Speaker 2>other value. You can assign them to variables, store them

628
00:30:31.799 --> 00:30:34.519
<v Speaker 2>in arrays or objects, pass them as arguments to other

629
00:30:34.559 --> 00:30:38.799
<v Speaker 2>functions callbacks, and return them from functions higher order functions.

630
00:30:39.039 --> 00:30:41.920
<v Speaker 2>This is fundamental to functional programming patterns in JS.

631
00:30:42.240 --> 00:30:45.440
<v Speaker 1>Very flexible. What about the caller property and the arguments

632
00:30:45.480 --> 00:30:47.039
<v Speaker 1>object still relevant?

633
00:30:47.240 --> 00:30:51.119
<v Speaker 2>The argument's object exists in non arrow functions. It's an

634
00:30:51.200 --> 00:30:54.799
<v Speaker 2>array like object holding all past arguments. But rest parameters

635
00:30:54.839 --> 00:30:57.319
<v Speaker 2>are generally preferred now because they give you a real array.

636
00:30:58.079 --> 00:31:01.640
<v Speaker 2>Arguments dot collie refers to the current function and arguments

637
00:31:01.640 --> 00:31:04.640
<v Speaker 2>dot caller or function dot caller refers to the calling

638
00:31:04.680 --> 00:31:08.720
<v Speaker 2>function are deprecated, non standard and forbidden in strict mode.

639
00:31:09.240 --> 00:31:10.480
<v Speaker 2>Avoid them good to know.

640
00:31:10.759 --> 00:31:15.640
<v Speaker 1>Stick with rest parameters. Finally, execution context, scope chain, and closure.

641
00:31:15.920 --> 00:31:19.759
<v Speaker 2>These sound deep, they are core concepts and execution context

642
00:31:19.799 --> 00:31:22.880
<v Speaker 2>is like the environment where code runs includes the variables

643
00:31:23.000 --> 00:31:25.920
<v Speaker 2>scope this value. When a function is called, a new

644
00:31:25.960 --> 00:31:29.279
<v Speaker 2>context is created. The scope chain, as we said, is

645
00:31:29.319 --> 00:31:32.160
<v Speaker 2>how JS looks up variables by checking the current scope,

646
00:31:32.359 --> 00:31:33.200
<v Speaker 2>then outer scopes.

647
00:31:33.440 --> 00:31:33.880
<v Speaker 1>Enclosure.

648
00:31:34.039 --> 00:31:36.960
<v Speaker 2>Closure is when a function remembers its lexical scope the

649
00:31:37.039 --> 00:31:39.839
<v Speaker 2>variables from the environment where it was created, even when

650
00:31:39.880 --> 00:31:42.880
<v Speaker 2>the function is executed outside that original scope, so an.

651
00:31:42.720 --> 00:31:46.160
<v Speaker 1>Inner function can still access the outer function's variables. After

652
00:31:46.200 --> 00:31:48.119
<v Speaker 1>the outer function has finished running.

653
00:31:48.119 --> 00:31:52.440
<v Speaker 2>Exactly, the inner function closes over the outer scope's variables.

654
00:31:52.839 --> 00:31:56.319
<v Speaker 2>This enables powerful patterns like data privacy, creating private like

655
00:31:56.400 --> 00:31:59.279
<v Speaker 2>variables and functions that maintain state between calls.

656
00:31:59.400 --> 00:32:04.720
<v Speaker 1>Closures are powerful. Okay, asynchronous JavaScript promises a better way

657
00:32:04.759 --> 00:32:05.960
<v Speaker 1>than callbacks.

658
00:32:05.519 --> 00:32:09.960
<v Speaker 2>Oh, definitely. Promises represent the eventual result of an ACINC operation.

659
00:32:10.799 --> 00:32:13.599
<v Speaker 2>A promise object is a placeholder for a future value.

660
00:32:13.920 --> 00:32:16.799
<v Speaker 2>It starts an appending state, and then it eventually settles

661
00:32:16.799 --> 00:32:20.039
<v Speaker 2>into either a fulfilled state if the operation succeeded with

662
00:32:20.039 --> 00:32:22.880
<v Speaker 2>the result value, or a rejected state if it failed

663
00:32:22.880 --> 00:32:23.920
<v Speaker 2>with an error or reason.

664
00:32:24.000 --> 00:32:24.960
<v Speaker 1>How do we create them?

665
00:32:25.319 --> 00:32:29.440
<v Speaker 2>Usually using new promise resolve reject inside that function the executor,

666
00:32:29.720 --> 00:32:32.000
<v Speaker 2>you perform your ACNC operation. When it's done, you call

667
00:32:32.039 --> 00:32:35.279
<v Speaker 2>resolve value on success or reject error on failure.

668
00:32:35.440 --> 00:32:37.920
<v Speaker 1>And how do we use the result or handle the error?

669
00:32:38.039 --> 00:32:40.359
<v Speaker 3>Then and dot catch Precisely.

670
00:32:39.920 --> 00:32:43.759
<v Speaker 2>You chain that on fulfilled unrejected onto a promise. Unfulfilled

671
00:32:43.799 --> 00:32:46.880
<v Speaker 2>runs if it resolves getting the value, on rejected runs

672
00:32:46.920 --> 00:32:50.039
<v Speaker 2>if it rejects getting the error catch unrejected is just

673
00:32:50.079 --> 00:32:53.559
<v Speaker 2>shorthand for that null unrejected, focusing.

674
00:32:53.119 --> 00:32:55.960
<v Speaker 1>Only on errors, and then returns another promise. That's how

675
00:32:56.000 --> 00:32:56.599
<v Speaker 1>chaining works.

676
00:32:56.720 --> 00:33:00.359
<v Speaker 2>Yes, each then or dot catch returns a new promise,

677
00:33:00.400 --> 00:33:03.200
<v Speaker 2>allowing you to chain asynchronous steps together in a much

678
00:33:03.279 --> 00:33:07.720
<v Speaker 2>cleaner way than nested callbacks callback hell. The handlers in

679
00:33:07.759 --> 00:33:10.759
<v Speaker 2>then are also non reentrant. They won't be called immediately

680
00:33:10.759 --> 00:33:12.680
<v Speaker 2>if the promise is already settled, they get cued.

681
00:33:13.119 --> 00:33:17.720
<v Speaker 1>Very elegant. What about managing multiple promises? Promise dot all

682
00:33:17.920 --> 00:33:19.240
<v Speaker 1>promise dot race.

683
00:33:19.200 --> 00:33:22.920
<v Speaker 2>Yeah, useful static methods. Promise dot all promises waits for

684
00:33:23.000 --> 00:33:26.599
<v Speaker 2>all promises in the input iterable to fulfill. If any

685
00:33:26.640 --> 00:33:29.440
<v Speaker 2>reject it rejects immediately, it resolves with an array of

686
00:33:29.440 --> 00:33:29.960
<v Speaker 2>the results.

687
00:33:30.079 --> 00:33:32.079
<v Speaker 1>Okay, waits for all successes.

688
00:33:32.200 --> 00:33:36.319
<v Speaker 2>Promise dot all settled promises waits for all promises to settle,

689
00:33:36.720 --> 00:33:40.119
<v Speaker 2>either fulfill or reject it always fulfills, returning an array

690
00:33:40.119 --> 00:33:42.359
<v Speaker 2>of objects describing the outcome of each promise.

691
00:33:42.519 --> 00:33:45.319
<v Speaker 1>Safer if you need to know about all outcomes, even failures.

692
00:33:45.480 --> 00:33:48.960
<v Speaker 2>Right. Promise dot race promises settles as soon as the

693
00:33:49.000 --> 00:33:52.279
<v Speaker 2>first promise in the terable settles either fulfills or rejects,

694
00:33:52.480 --> 00:33:54.079
<v Speaker 2>It takes on the outcome of that first one, a

695
00:33:54.119 --> 00:33:58.039
<v Speaker 2>race to the finish and promise. Any promises resolves as

696
00:33:58.039 --> 00:34:01.000
<v Speaker 2>soon as the first promise fulfills. It only rejects if

697
00:34:01.039 --> 00:34:04.599
<v Speaker 2>all promises reject and it rejects with a special aggregate error.

698
00:34:04.880 --> 00:34:08.039
<v Speaker 1>Useful if you just need one success out of many possibilities.

699
00:34:08.480 --> 00:34:12.800
<v Speaker 1>What about serial promise composition executing promises one after another.

700
00:34:13.000 --> 00:34:16.039
<v Speaker 2>That's often just standard dend chaining. You ensure one acinc

701
00:34:16.079 --> 00:34:19.519
<v Speaker 2>operation completes before starting the next, often passing the result

702
00:34:19.519 --> 00:34:22.519
<v Speaker 2>along a synca weight makes this look even more sequential.

703
00:34:23.119 --> 00:34:26.320
<v Speaker 1>Speaking of timing the micro test queue, how does that

704
00:34:26.360 --> 00:34:27.280
<v Speaker 1>affect promises?

705
00:34:27.679 --> 00:34:31.119
<v Speaker 2>Promise dot then and dot catch callbacks don't run immediately

706
00:34:31.639 --> 00:34:34.480
<v Speaker 2>when a promise settles, its handlers are scheduled to run

707
00:34:34.480 --> 00:34:37.760
<v Speaker 2>in the micro task queue. This queue has higher priority

708
00:34:37.800 --> 00:34:40.199
<v Speaker 2>than the main macro task queue, which handles things like

709
00:34:40.480 --> 00:34:42.480
<v Speaker 2>set time out or user events.

710
00:34:42.239 --> 00:34:45.280
<v Speaker 1>So promise callbacks run very soon after the current synchronous

711
00:34:45.280 --> 00:34:47.960
<v Speaker 1>code finishes, but before the next timer.

712
00:34:47.800 --> 00:34:51.320
<v Speaker 2>Or event exactly. It ensures a predictable execution order for

713
00:34:51.360 --> 00:34:54.639
<v Speaker 2>promise reactions happening after the current task but before the

714
00:34:54.679 --> 00:34:57.199
<v Speaker 2>browser does other things like rendering got it?

715
00:34:57.280 --> 00:34:59.880
<v Speaker 1>And why is it crucial to avoid unhandled rejection?

716
00:35:00.519 --> 00:35:04.159
<v Speaker 2>If a promise rejects and nothing catches that rejection you

717
00:35:04.280 --> 00:35:08.159
<v Speaker 2>dot catch or unrejected handler in a dot catch, then

718
00:35:08.719 --> 00:35:13.119
<v Speaker 2>it's an unhandled rejection. Modern environments will log errors to

719
00:35:13.159 --> 00:35:16.079
<v Speaker 2>the console, and in some cases, like no JS, it

720
00:35:16.159 --> 00:35:19.000
<v Speaker 2>might even terminate the process. You always want to handle

721
00:35:19.079 --> 00:35:21.280
<v Speaker 2>potential errors to keep your application stable.

722
00:35:21.280 --> 00:35:23.519
<v Speaker 1>I always have a dot catch somewhere down the chain.

723
00:35:24.119 --> 00:35:28.559
<v Speaker 1>What about promise extensions like cancelation or progress? Are those standard?

724
00:35:28.760 --> 00:35:32.480
<v Speaker 2>No, they aren't part of the official trauma specification. Cancelation

725
00:35:32.920 --> 00:35:36.079
<v Speaker 2>the ability to stop an ongoing async operation tied to

726
00:35:36.119 --> 00:35:40.920
<v Speaker 2>a promise, and progress notifications getting updates before it finishes

727
00:35:41.239 --> 00:35:44.239
<v Speaker 2>are things you usually implement with libraries or custom patterns,

728
00:35:44.480 --> 00:35:47.280
<v Speaker 2>often using mechanisms like the abort controller, which we'll touch

729
00:35:47.280 --> 00:35:47.880
<v Speaker 2>on with fetch.

730
00:35:47.920 --> 00:35:50.480
<v Speaker 1>Okay, so not built in now? Asinc and a weight

731
00:35:50.679 --> 00:35:53.360
<v Speaker 1>this is syntactic sugar on top of promises right makes

732
00:35:53.599 --> 00:35:55.559
<v Speaker 1>ACYNC code look synchronous exactly.

733
00:35:55.639 --> 00:35:58.840
<v Speaker 2>You mark a function with the acinc keyword inside that function,

734
00:35:59.039 --> 00:36:01.159
<v Speaker 2>you can use the awake word before a promise.

735
00:36:01.239 --> 00:36:02.079
<v Speaker 1>And what does a weight do?

736
00:36:02.800 --> 00:36:05.480
<v Speaker 2>It? Pauses the execution of the acing function at that

737
00:36:05.519 --> 00:36:08.119
<v Speaker 2>point until the promise you're awaiting settles.

738
00:36:08.280 --> 00:36:10.320
<v Speaker 1>Pauses the function, not the whole browser, just.

739
00:36:10.320 --> 00:36:14.360
<v Speaker 2>The acing function. It asynchronously waits if the promise fulfills

740
00:36:14.800 --> 00:36:17.679
<v Speaker 2>a weight, returns is the result value. If the promise

741
00:36:17.719 --> 00:36:21.440
<v Speaker 2>rejects a weight, throws that rejection reason as an error.

742
00:36:21.760 --> 00:36:24.079
<v Speaker 1>So you can use try dot catch around awake.

743
00:36:24.280 --> 00:36:27.079
<v Speaker 2>Yes, that's the beauty. You can use standard try dot

744
00:36:27.119 --> 00:36:30.679
<v Speaker 2>catch dot finally blocks for error handling. Just like synchronous code,

745
00:36:31.000 --> 00:36:34.400
<v Speaker 2>an ACYNC function itself implicitly returns a promise that resolves

746
00:36:34.400 --> 00:36:37.840
<v Speaker 2>with the function's return value or rejects if an uncaught

747
00:36:37.920 --> 00:36:38.960
<v Speaker 2>error occurs inside it.

748
00:36:39.000 --> 00:36:41.039
<v Speaker 1>That sounds much easier to read and write than loss

749
00:36:41.039 --> 00:36:43.039
<v Speaker 1>of dot chains. Where can we use.

750
00:36:42.880 --> 00:36:45.800
<v Speaker 2>A weight only directly inside an acing function? You can't

751
00:36:45.840 --> 00:36:48.880
<v Speaker 2>just sprinkle a weight anywhere In regular synchronous code. You

752
00:36:48.920 --> 00:36:53.079
<v Speaker 2>might use an immediately invoked acing function expression iiaff e

753
00:36:53.719 --> 00:36:55.800
<v Speaker 2>like acink a weight to use a weight at the

754
00:36:55.800 --> 00:36:57.400
<v Speaker 2>top level of a module if needed.

755
00:36:57.519 --> 00:37:02.599
<v Speaker 1>Gotcha. So for serial execution, instead of then, we just await, await, await.

756
00:37:02.360 --> 00:37:05.000
<v Speaker 2>Pretty much concer result one will await step one const

757
00:37:05.000 --> 00:37:08.079
<v Speaker 2>result two. Await step two Result one looks very linear

758
00:37:08.119 --> 00:37:08.480
<v Speaker 2>and clear.

759
00:37:08.760 --> 00:37:12.159
<v Speaker 1>Fantastic. What about running things in parallel with they sink away,

760
00:37:12.199 --> 00:37:16.840
<v Speaker 1>but handling errors safely rejection safe parallelization.

761
00:37:16.719 --> 00:37:19.880
<v Speaker 2>Right if you just await promise dot all P one,

762
00:37:19.920 --> 00:37:22.800
<v Speaker 2>P two, p three, the whole thing rejects if any

763
00:37:22.800 --> 00:37:25.079
<v Speaker 2>of them reject. If you want to get results even

764
00:37:25.079 --> 00:37:27.880
<v Speaker 2>if some fail, you could await promise dot all settled,

765
00:37:28.159 --> 00:37:30.360
<v Speaker 2>which always results and tells you the status of each.

766
00:37:31.039 --> 00:37:34.480
<v Speaker 2>Or you could map your promises and handle errors individually,

767
00:37:34.880 --> 00:37:37.920
<v Speaker 2>perhaps using a weight p dot catch EP do or

768
00:37:38.480 --> 00:37:41.639
<v Speaker 2>within the mapping or wrapping awights in individual try dot

769
00:37:41.719 --> 00:37:43.679
<v Speaker 2>catch blocks if doing them sequentially.

770
00:37:43.719 --> 00:37:47.639
<v Speaker 1>So options exist to manage parallel tasks gracefully even with failures. Great.

771
00:37:47.960 --> 00:37:50.639
<v Speaker 1>Let's shift to the browser environment itself, the browser object

772
00:37:50.679 --> 00:37:52.400
<v Speaker 1>model BOM. What does this cover?

773
00:37:52.800 --> 00:37:55.760
<v Speaker 2>The BOMB represents the browser window and its features, distinct

774
00:37:55.760 --> 00:37:59.119
<v Speaker 2>from the HTML document content, which is the DOM. The

775
00:37:59.159 --> 00:38:01.960
<v Speaker 2>core object is which is the global object.

776
00:38:01.719 --> 00:38:03.559
<v Speaker 1>In browsers, and we can find out where the user.

777
00:38:03.440 --> 00:38:07.159
<v Speaker 2>Has scrolled YEP, window dot scroll x or paychecks offset

778
00:38:07.239 --> 00:38:09.280
<v Speaker 2>and window dust scrolly or pageops. I could give you

779
00:38:09.280 --> 00:38:11.639
<v Speaker 2>the horizontal and vertical scroll positions in pixels.

780
00:38:11.679 --> 00:38:14.440
<v Speaker 1>What about opening new windows? Window dot open pop up

781
00:38:14.480 --> 00:38:15.480
<v Speaker 1>blockers are a thing.

782
00:38:15.320 --> 00:38:19.960
<v Speaker 2>Though they are Window dot open ural name features tries

783
00:38:20.000 --> 00:38:22.719
<v Speaker 2>to open a new window or tab, but browsers usually

784
00:38:22.719 --> 00:38:25.360
<v Speaker 2>block this unless it happens right after a direct user

785
00:38:25.400 --> 00:38:28.760
<v Speaker 2>action like a click. You must check the return value

786
00:38:28.800 --> 00:38:31.880
<v Speaker 2>of window dot open. If it's null, the pop up

787
00:38:31.960 --> 00:38:32.800
<v Speaker 2>was likely blocked.

788
00:38:32.840 --> 00:38:35.920
<v Speaker 1>Good check. Timers set time out and set interval. How

789
00:38:35.920 --> 00:38:37.559
<v Speaker 1>do they work with the single thread.

790
00:38:37.519 --> 00:38:40.800
<v Speaker 2>Set time out callback delay runs the callback once after

791
00:38:40.840 --> 00:38:44.559
<v Speaker 2>at least delay milliseconds. Set interval runs the callback repeatedly

792
00:38:44.599 --> 00:38:48.360
<v Speaker 2>every interval milliseconds. Because JavaScript is single threaded and uses

793
00:38:48.360 --> 00:38:51.320
<v Speaker 2>an event loop, the delay is a minimum. The callback

794
00:38:51.360 --> 00:38:53.760
<v Speaker 2>actually runs only when the main thread is free after

795
00:38:53.760 --> 00:38:56.440
<v Speaker 2>the delay is passed. Set time out returns an ID

796
00:38:56.559 --> 00:38:59.000
<v Speaker 2>you can pass to clear timeout to cancel it. Set

797
00:38:59.039 --> 00:39:00.880
<v Speaker 2>interval returns an id for clear.

798
00:39:00.599 --> 00:39:04.280
<v Speaker 1>Interval minimum delay not exact. Dot IT navigation, location and

799
00:39:04.320 --> 00:39:05.079
<v Speaker 1>history oobjects.

800
00:39:05.400 --> 00:39:09.400
<v Speaker 2>Location gives info about the current url location dot href, location,

801
00:39:09.480 --> 00:39:12.480
<v Speaker 2>dot path name, location, dot searchlocation, dot hash, et cetera,

802
00:39:12.880 --> 00:39:15.280
<v Speaker 2>and lets you navigate by assigning to location dot h

803
00:39:15.320 --> 00:39:18.760
<v Speaker 2>ref or using methods like location dot sign. You all

804
00:39:18.880 --> 00:39:22.760
<v Speaker 2>navigates and ads to history location dot replace, heural navigates

805
00:39:22.800 --> 00:39:25.719
<v Speaker 2>but replaces current history entry and location dot reload and

806
00:39:25.880 --> 00:39:28.360
<v Speaker 2>history history lets you move through the user session history

807
00:39:28.400 --> 00:39:31.679
<v Speaker 2>dot backstory, dot forward history dot go in where N

808
00:39:31.760 --> 00:39:34.360
<v Speaker 2>can be positive or negative. History dot link tells you

809
00:39:34.400 --> 00:39:35.239
<v Speaker 2>how many items are in.

810
00:39:35.239 --> 00:39:38.639
<v Speaker 1>The history stack, useful for custom back forward buttons. What

811
00:39:38.679 --> 00:39:41.079
<v Speaker 1>about the navigator object? What browserinfo does it?

812
00:39:41.119 --> 00:39:45.519
<v Speaker 2>Whole navigator gives you browsersniffinginfo, though user agent is notoriously unreliable.

813
00:39:45.880 --> 00:39:49.360
<v Speaker 2>Better info comes from properties like Navigator dot Language, Navigator

814
00:39:49.360 --> 00:39:53.119
<v Speaker 2>dot platform. Crucially, it has Navigator dot online booley in

815
00:39:53.199 --> 00:39:56.800
<v Speaker 2>for connection status and events online offline. The Navigator Dot

816
00:39:56.800 --> 00:40:01.079
<v Speaker 2>Connection object Network Information API provides more tas like connection type,

817
00:40:01.079 --> 00:40:05.079
<v Speaker 2>effective type, speed, downlink rtt OTT and a change event.

818
00:40:05.159 --> 00:40:08.239
<v Speaker 1>Network INFOS sounds handy, and the screen object.

819
00:40:08.079 --> 00:40:10.800
<v Speaker 2>Screen tells you about the users display screen dot width,

820
00:40:10.840 --> 00:40:14.400
<v Speaker 2>screen dot height, screen dot availwith excluding os interfaces, screen

821
00:40:14.440 --> 00:40:18.239
<v Speaker 2>dot color depth, screen dotpixel depth, screen dot orientation.

822
00:40:18.159 --> 00:40:21.639
<v Speaker 1>Good for responsive design decisions. Can we control audio and

823
00:40:21.719 --> 00:40:22.440
<v Speaker 1>video via.

824
00:40:22.360 --> 00:40:25.800
<v Speaker 2>The bo yes HTML media elements Audio video have a

825
00:40:25.920 --> 00:40:30.599
<v Speaker 2>rich JavaScript API. You can play, pause, control volume, get duration,

826
00:40:30.719 --> 00:40:33.400
<v Speaker 2>get and set current time. They fire lots of events

827
00:40:33.639 --> 00:40:37.480
<v Speaker 2>play pause and a time update, canplay error, etc. You

828
00:40:37.480 --> 00:40:40.880
<v Speaker 2>can use canplay type mime type to check codec support.

829
00:40:40.880 --> 00:40:44.920
<v Speaker 1>Full media control. The URL object better than string manipulation

830
00:40:45.119 --> 00:40:45.559
<v Speaker 1>much better.

831
00:40:45.679 --> 00:40:48.400
<v Speaker 2>New url string parses a URL string into an object

832
00:40:48.480 --> 00:40:52.039
<v Speaker 2>with properties for easy access to protocol, host name, path, names, search, hash,

833
00:40:52.039 --> 00:40:54.920
<v Speaker 2>et cetera. It also has search perms and objects specifically

834
00:40:54.920 --> 00:40:57.440
<v Speaker 2>for manipulating query string parameters easily.

835
00:40:57.199 --> 00:40:59.880
<v Speaker 1>Nice and performance monitoring dot performance dot.

836
00:40:59.719 --> 00:41:02.800
<v Speaker 2>Now Yeah, the performance API is key for measuring speed.

837
00:41:03.360 --> 00:41:07.280
<v Speaker 2>Performance dot now gives high resolution timestamps. You can create

838
00:41:07.360 --> 00:41:11.440
<v Speaker 2>name markers with performance dot mark start task, measure durations

839
00:41:11.440 --> 00:41:14.480
<v Speaker 2>between marks with performance dot measure task duration, start task

840
00:41:14.599 --> 00:41:17.960
<v Speaker 2>and task and retrieve these entries with performance dot get entries.

841
00:41:19.039 --> 00:41:23.519
<v Speaker 2>The Navigation Timing API Performance Navigation Timing gives detailed timings

842
00:41:23.519 --> 00:41:24.840
<v Speaker 2>for pageload.

843
00:41:24.280 --> 00:41:27.800
<v Speaker 1>Stages, essential for optimization. Okay, let's switch to the Document

844
00:41:27.840 --> 00:41:31.199
<v Speaker 1>Object Model DOM. This is about the page content itself,

845
00:41:31.239 --> 00:41:33.159
<v Speaker 1>the HTML structure exactly.

846
00:41:33.360 --> 00:41:39.360
<v Speaker 2>The DOM represents the HTML document as a tree of nodes, elements, text, comments, attributes.

847
00:41:39.599 --> 00:41:40.840
<v Speaker 2>The document object is.

848
00:41:40.800 --> 00:41:43.280
<v Speaker 1>The root, and nodes have properties and relationships.

849
00:41:43.360 --> 00:41:45.840
<v Speaker 2>Yep. Node type tells you what it is, element, texts

850
00:41:45.840 --> 00:41:48.199
<v Speaker 2>et cetera. Note name gives the tag name for elements.

851
00:41:48.280 --> 00:41:51.400
<v Speaker 2>Node value gives the content for text nodes. Relationships like

852
00:41:51.440 --> 00:41:54.360
<v Speaker 2>parent node child nodes first child, last child, next sibling,

853
00:41:54.400 --> 00:41:57.119
<v Speaker 2>previous sibling. Let you navigate this tree structure.

854
00:41:57.199 --> 00:42:00.280
<v Speaker 1>How do we grab specific elements? To start with? Element

855
00:42:00.360 --> 00:42:01.039
<v Speaker 1>by id.

856
00:42:01.079 --> 00:42:04.119
<v Speaker 2>That's a classic for unique ideas. Get elements by tag

857
00:42:04.199 --> 00:42:07.119
<v Speaker 2>name gets a live HTML collection of elements by tag.

858
00:42:07.440 --> 00:42:09.760
<v Speaker 2>Get elements by name gets a live nodalist by the

859
00:42:09.800 --> 00:42:13.719
<v Speaker 2>name attribute. There's also document dot, document element, the h

860
00:42:13.800 --> 00:42:16.159
<v Speaker 2>nolande and document dot body.

861
00:42:15.960 --> 00:42:18.000
<v Speaker 1>Right different ways to get elements. How do we change

862
00:42:18.000 --> 00:42:19.760
<v Speaker 1>things add or remove nodes.

863
00:42:19.840 --> 00:42:22.679
<v Speaker 2>You can document dot create element tag name and document

864
00:42:22.760 --> 00:42:26.039
<v Speaker 2>dot create text node, then use parentode dot a pen

865
00:42:26.159 --> 00:42:28.320
<v Speaker 2>child new node to add it at the end, or

866
00:42:28.440 --> 00:42:31.840
<v Speaker 2>parentnode dot insert before new node, reference node to insert

867
00:42:31.880 --> 00:42:34.960
<v Speaker 2>before another node. Use parentnode dot remove child node to

868
00:42:35.039 --> 00:42:37.760
<v Speaker 2>remove and parentode dot replace child new node old node

869
00:42:37.800 --> 00:42:41.320
<v Speaker 2>to replace document dot create. Document fragment is useful for

870
00:42:41.360 --> 00:42:44.039
<v Speaker 2>building a chunk of dom off screen before appending it

871
00:42:44.039 --> 00:42:45.480
<v Speaker 2>all at once for better performance.

872
00:42:45.639 --> 00:42:48.760
<v Speaker 1>Document fragments for batch updates. Good tip what about using

873
00:42:48.840 --> 00:42:51.599
<v Speaker 1>CSS selectors dot query selector yes.

874
00:42:51.679 --> 00:42:54.920
<v Speaker 2>Query selector selector returns the first matching element, and query

875
00:42:55.000 --> 00:42:58.199
<v Speaker 2>selectora selector returns a static nodalist of all matching elements.

876
00:42:58.440 --> 00:43:01.679
<v Speaker 2>These are incredibly powerful on it available on document fragments

877
00:43:01.679 --> 00:43:04.719
<v Speaker 2>and individual elements, much more flexible than the older get

878
00:43:04.719 --> 00:43:06.159
<v Speaker 2>elements by methods and.

879
00:43:06.159 --> 00:43:07.880
<v Speaker 1>Get elements by class name was added later.

880
00:43:08.000 --> 00:43:10.119
<v Speaker 2>Right get elements by class named it gets a live

881
00:43:10.320 --> 00:43:13.280
<v Speaker 2>HTML collection based on class names, also useful.

882
00:43:13.440 --> 00:43:15.840
<v Speaker 1>Okay, we have the element, how do we change its content?

883
00:43:16.320 --> 00:43:17.920
<v Speaker 1>Inner HTML, text content, etc.

884
00:43:18.360 --> 00:43:22.400
<v Speaker 2>Inner HTML gets or sets the HTML content inside an element.

885
00:43:22.840 --> 00:43:27.079
<v Speaker 2>Setting it parses the string as HTML. Outer HTML includes

886
00:43:27.119 --> 00:43:30.599
<v Speaker 2>the element itself. Text content gets or sets only the

887
00:43:30.639 --> 00:43:34.679
<v Speaker 2>text content, ignoring HTML tags and encoding entities when setting.

888
00:43:35.159 --> 00:43:37.679
<v Speaker 2>Intertext is similar to text content, but is aware of

889
00:43:37.719 --> 00:43:42.559
<v Speaker 2>CSS rendering. It omits hidden text and also codes entities differently.

890
00:43:43.039 --> 00:43:45.199
<v Speaker 2>Be careful with inner HTML as it can be slow

891
00:43:45.320 --> 00:43:48.440
<v Speaker 2>and requires reattaching event listeners to recreated elements.

892
00:43:48.519 --> 00:43:51.679
<v Speaker 1>Good point about listeners. How do we change styles? Dot element, dot.

893
00:43:51.559 --> 00:43:55.039
<v Speaker 2>Style, element dot style accesses the elements inline style attribute.

894
00:43:55.119 --> 00:43:57.719
<v Speaker 2>You set properties like element dot style, dot background color

895
00:43:57.800 --> 00:44:00.559
<v Speaker 2>red to get the actual computed style including styles from

896
00:44:00.599 --> 00:44:04.119
<v Speaker 2>CSS rules. Use window dot get computed style element. You

897
00:44:04.119 --> 00:44:06.880
<v Speaker 2>can also access style sheets via document dot style sheets

898
00:44:06.880 --> 00:44:10.480
<v Speaker 2>and manipulate CSS rules, CSS rule CSS style directly, though

899
00:44:10.480 --> 00:44:11.360
<v Speaker 2>that's less common.

900
00:44:11.559 --> 00:44:15.440
<v Speaker 1>Inline versus computed style makes sense. What about element size

901
00:44:15.480 --> 00:44:18.039
<v Speaker 1>and position offset client scroll.

902
00:44:17.719 --> 00:44:21.239
<v Speaker 2>Dimensions to give different measurements offset offset offset with offset

903
00:44:21.320 --> 00:44:25.280
<v Speaker 2>left offset top includes borders and padding and position relative

904
00:44:25.320 --> 00:44:29.199
<v Speaker 2>to the offset parent client client height client with is

905
00:44:29.239 --> 00:44:34.719
<v Speaker 2>the inner size, padding included, border, scroll bars excluded, scroll

906
00:44:34.760 --> 00:44:38.119
<v Speaker 2>height scroll width is the total size of the scrollable content,

907
00:44:38.360 --> 00:44:41.599
<v Speaker 2>while scroll left scroll top is the current scroll position

908
00:44:41.679 --> 00:44:44.199
<v Speaker 2>within the element. Client dimensions are read.

909
00:44:44.039 --> 00:44:46.960
<v Speaker 1>Only different numbers for different use cases. What if we

910
00:44:47.000 --> 00:44:50.360
<v Speaker 1>need more advanced dom traversal no iterator and tree walker.

911
00:44:50.440 --> 00:44:53.239
<v Speaker 2>These are for more complex iteration needs. They let you

912
00:44:53.280 --> 00:44:56.519
<v Speaker 2>traverse a subtree of the dome, optionally filtering nodes based

913
00:44:56.559 --> 00:44:59.440
<v Speaker 2>on criteria you define, especially tree walker, which has a

914
00:44:59.440 --> 00:45:02.559
<v Speaker 2>filter function. They give you finer control than simple loops

915
00:45:02.599 --> 00:45:05.480
<v Speaker 2>or recursive functions. Sometimes true walker keeps track of the

916
00:45:05.480 --> 00:45:05.920
<v Speaker 2>current node.

917
00:45:06.239 --> 00:45:10.719
<v Speaker 1>Specialized tools and DOM ranges selecting parts of the document.

918
00:45:10.960 --> 00:45:14.920
<v Speaker 2>Yeah. Document dot creator range creates a range object representing

919
00:45:14.920 --> 00:45:17.760
<v Speaker 2>a contiguous section of the document, you can set its

920
00:45:17.760 --> 00:45:21.039
<v Speaker 2>start and end points. Set start, set end. Then you

921
00:45:21.079 --> 00:45:25.000
<v Speaker 2>can manipulate that selected content. Delete contents, extract contents into

922
00:45:25.000 --> 00:45:28.559
<v Speaker 2>a document fragment, clone contents, and certain nodes around contents.

923
00:45:29.000 --> 00:45:31.239
<v Speaker 2>Useful for things like text editors or highlighting.

924
00:45:31.400 --> 00:45:36.800
<v Speaker 1>Powerful selection manipulation. Lastly, for DOM intersection observer and resize

925
00:45:36.840 --> 00:45:41.239
<v Speaker 1>observer modern ways to react to visibility and size changes.

926
00:45:40.880 --> 00:45:45.719
<v Speaker 2>Exactly intersection observer new intersection Observer callback efficiently tells you

927
00:45:45.760 --> 00:45:48.760
<v Speaker 2>when an element intersects with the viewport or another development.

928
00:45:49.079 --> 00:45:52.800
<v Speaker 2>Great for lazy loading images, infinite scroll triggering animations on

929
00:45:52.880 --> 00:45:56.800
<v Speaker 2>view resize observer new resize observer callback efficiently tells you

930
00:45:56.840 --> 00:45:59.280
<v Speaker 2>when an element size changes, much better than pulling off

931
00:45:59.320 --> 00:46:02.440
<v Speaker 2>stwidth constantly. Both are asynchronous in performance focus.

932
00:46:02.559 --> 00:46:05.760
<v Speaker 1>Do you sound like essential modern tools? Okay? Events making

933
00:46:05.760 --> 00:46:07.960
<v Speaker 1>pages interactive? DON level zero Level two.

934
00:46:08.239 --> 00:46:10.840
<v Speaker 2>DOM level zero is the old way. Element dot on

935
00:46:10.920 --> 00:46:14.639
<v Speaker 2>click will function simple, but only one handler per event

936
00:46:14.679 --> 00:46:17.480
<v Speaker 2>type and only runs in the bubbling phase. This inside

937
00:46:17.519 --> 00:46:19.719
<v Speaker 2>is the element removed by setting to NOL and.

938
00:46:19.760 --> 00:46:21.280
<v Speaker 1>Level two the modern way.

939
00:46:21.400 --> 00:46:25.320
<v Speaker 2>DOM level two introduced element dot ad event listener type listener,

940
00:46:25.400 --> 00:46:28.519
<v Speaker 2>use capture This is the standard. You can add multiple listeners.

941
00:46:28.960 --> 00:46:31.880
<v Speaker 2>The third argument use capture boolli in or options object

942
00:46:32.159 --> 00:46:34.440
<v Speaker 2>lets you choose whether to listen during the capturing phase

943
00:46:34.719 --> 00:46:37.239
<v Speaker 2>down the tree or the bubbling phase up the tree.

944
00:46:37.320 --> 00:46:40.639
<v Speaker 2>The default you remove listeners with remove event listener, needing

945
00:46:40.639 --> 00:46:41.679
<v Speaker 2>the exact same arguments.

946
00:46:41.760 --> 00:46:43.840
<v Speaker 1>AD event listener is the way to go. When an

947
00:46:43.840 --> 00:46:46.559
<v Speaker 1>event happens, we get an event object. What's in it?

948
00:46:46.960 --> 00:46:49.559
<v Speaker 2>Lots of useful stuff? Event dot type like click, event

949
00:46:49.599 --> 00:46:52.400
<v Speaker 2>dot target, the element the event originated on, event dot

950
00:46:52.480 --> 00:46:55.079
<v Speaker 2>current target the element the listener is attached to. Event

951
00:46:55.119 --> 00:46:58.400
<v Speaker 2>dot prevent default, stop to full browseractions, event dot stop

952
00:46:58.400 --> 00:47:05.039
<v Speaker 2>propagation to stop bubbling cap Also details like coordinates, client x, clinyy, modifier, keys, feature,

953
00:47:05.119 --> 00:47:08.440
<v Speaker 2>l key, old key, event phase, et cetera. Properties vary

954
00:47:08.480 --> 00:47:09.519
<v Speaker 2>a bit by event type.

955
00:47:09.679 --> 00:47:12.400
<v Speaker 1>Lots of context. What are some common event types we handle?

956
00:47:12.679 --> 00:47:16.440
<v Speaker 2>Oh tons load for window, images of scripts, unload, window focused,

957
00:47:16.440 --> 00:47:19.960
<v Speaker 2>blur or form fields, window, mouse, events, click, TVL click, mousedown,

958
00:47:19.960 --> 00:47:22.599
<v Speaker 2>mouse oup, mouse over, mouse out, mouse enter, mouse leave wheel,

959
00:47:22.840 --> 00:47:25.599
<v Speaker 2>keyboard events, key down, keep us key at form events, submit,

960
00:47:25.960 --> 00:47:30.239
<v Speaker 2>change input, clipboard events, touch events, many more.

961
00:47:30.360 --> 00:47:33.480
<v Speaker 1>A whole universe of events. Can we trigger events ourselves

962
00:47:33.480 --> 00:47:34.880
<v Speaker 1>in code simulate them?

963
00:47:35.039 --> 00:47:38.400
<v Speaker 2>Yes, it's a bit verbose. Use document dot create event

964
00:47:38.559 --> 00:47:41.599
<v Speaker 2>like mouse events, then initialize it with details using a

965
00:47:41.639 --> 00:47:44.119
<v Speaker 2>method like event dot inn at mouse event or newer

966
00:47:44.159 --> 00:47:47.199
<v Speaker 2>constructors like new mouse event or new custom event. Finally,

967
00:47:47.280 --> 00:47:50.320
<v Speaker 2>dispatch it on an element using element dot dispatch.

968
00:47:50.000 --> 00:47:54.639
<v Speaker 1>Event create initialized dispatch guid. For smooth animations, request animation frame.

969
00:47:54.679 --> 00:47:55.320
<v Speaker 3>How did that work?

970
00:47:55.559 --> 00:47:59.280
<v Speaker 2>Instead of timers like set timeout, use request animation frame callback.

971
00:47:59.599 --> 00:48:02.320
<v Speaker 2>The brow sol so calls your callback function just before

972
00:48:02.360 --> 00:48:04.840
<v Speaker 2>it's about to repaint the screen. The sinks your animation

973
00:48:04.920 --> 00:48:08.199
<v Speaker 2>logic perfectly with the browser's rendering cycle, making animations much

974
00:48:08.239 --> 00:48:11.320
<v Speaker 2>smoother and more efficient. It passes a high resolution timestamp

975
00:48:11.360 --> 00:48:13.920
<v Speaker 2>to the callback. You call it recursively within the callback

976
00:48:14.159 --> 00:48:17.199
<v Speaker 2>to continue the animation loop. Use cancel animation frame to

977
00:48:17.199 --> 00:48:17.559
<v Speaker 2>stop it.

978
00:48:17.719 --> 00:48:19.440
<v Speaker 1>Perfect for performance animations.

979
00:48:19.719 --> 00:48:20.039
<v Speaker 3>Okay.

980
00:48:20.199 --> 00:48:22.800
<v Speaker 1>HTML five APIs canvas for drawing.

981
00:48:22.880 --> 00:48:25.119
<v Speaker 2>Yes, the canvas element gives you a drawing surface. You

982
00:48:25.159 --> 00:48:27.719
<v Speaker 2>get the two D context with canvas dot get context

983
00:48:27.840 --> 00:48:30.679
<v Speaker 2>two D. This context object has tons of methods for

984
00:48:30.760 --> 00:48:34.400
<v Speaker 2>drawing shapes, rectangles, lines, arcs, curves with begin path moved

985
00:48:34.400 --> 00:48:37.400
<v Speaker 2>to a line to arc et cetera. Filling, fil style, fill, stroking,

986
00:48:37.440 --> 00:48:42.199
<v Speaker 2>stroke style, stroke struck, drawing text on fill text, applying transformations, translate, rotate, scale,

987
00:48:42.360 --> 00:48:46.159
<v Speaker 2>drawing images, dramage, adding shadows, gradients, patterns, clipping, compositing, global

988
00:48:46.159 --> 00:48:50.119
<v Speaker 2>composite operation and even pixel manipulation. Get image data, put

989
00:48:50.119 --> 00:48:51.199
<v Speaker 2>image data wow.

990
00:48:51.039 --> 00:48:53.360
<v Speaker 1>Full two D graphics engine and WebGL for three D

991
00:48:53.599 --> 00:48:55.079
<v Speaker 1>also on canvas.

992
00:48:54.840 --> 00:48:58.320
<v Speaker 2>YEP, canvas, dot get context, WEBNIL or webjail two. It's

993
00:48:58.320 --> 00:49:02.079
<v Speaker 2>based on OPENNGLS, providing low level access to the GPU

994
00:49:02.199 --> 00:49:05.039
<v Speaker 2>for hardware accelerated two D and three D graphics. You

995
00:49:05.079 --> 00:49:09.119
<v Speaker 2>define geometry in buffers, write vertex and fragment shaders in GLSL,

996
00:49:09.519 --> 00:49:12.920
<v Speaker 2>link them into programs, past data via attributes and uniforms,

997
00:49:13.239 --> 00:49:17.039
<v Speaker 2>and then issue draw calls, drawrays, draw elements. Much more

998
00:49:17.039 --> 00:49:20.199
<v Speaker 2>complex than two D canvas, but incredibly powerful.

999
00:49:19.920 --> 00:49:22.280
<v Speaker 1>High performance three D on the web. Forms got upgrades

1000
00:49:22.320 --> 00:49:25.639
<v Speaker 1>in HTML five to two, new types, validation, big.

1001
00:49:25.480 --> 00:49:28.360
<v Speaker 2>Time, new input types like email, earle date number with

1002
00:49:28.440 --> 00:49:32.079
<v Speaker 2>built in UI and validation attributes like required pattern min max,

1003
00:49:32.400 --> 00:49:37.000
<v Speaker 2>the constraint validation API element dot validity, element dot check, validity,

1004
00:49:37.079 --> 00:49:40.360
<v Speaker 2>element dot set custom validity, the invalid event programmatic submission

1005
00:49:40.360 --> 00:49:44.400
<v Speaker 2>with form dot submit. Fans like input change, clipboard events, copycut, paste,

1006
00:49:44.559 --> 00:49:47.480
<v Speaker 2>ridge text editing via the content editor attribute and document

1007
00:49:47.519 --> 00:49:49.960
<v Speaker 2>dot exec command, though the latter is getting replaced by

1008
00:49:50.000 --> 00:49:52.639
<v Speaker 2>newer APIs. So like boxes also have a good API

1009
00:49:52.639 --> 00:49:53.719
<v Speaker 2>from manipulating options.

1010
00:49:53.800 --> 00:49:57.000
<v Speaker 1>Forms are much smarter now, Okay, shifting to general JavaScript

1011
00:49:57.000 --> 00:49:59.960
<v Speaker 1>APIs atomics and shared airy buffer for worker community.

1012
00:50:00.360 --> 00:50:03.639
<v Speaker 2>Yes. This enables shared memory between multiple web workers and

1013
00:50:03.880 --> 00:50:06.800
<v Speaker 2>the main thread shared The rebuffer is a buffer whose

1014
00:50:06.880 --> 00:50:10.880
<v Speaker 2>underlying memory can be accessed by multiple threads simultaneously. Atomics

1015
00:50:10.920 --> 00:50:14.239
<v Speaker 2>provide special functions atomics, dot ad atomics, dot load atomics,

1016
00:50:14.239 --> 00:50:17.119
<v Speaker 2>dot store atomics, dot weight atomics, dot notify, et cetera

1017
00:50:17.440 --> 00:50:21.000
<v Speaker 2>that perform operations on that shared memory in an atomic way,

1018
00:50:21.199 --> 00:50:25.400
<v Speaker 2>preventing race conditions and ensuring operations aren't interrupted. Very advanced,

1019
00:50:25.480 --> 00:50:27.480
<v Speaker 2>high performance stuff for parallel computation.

1020
00:50:27.639 --> 00:50:32.199
<v Speaker 1>Shared memory powerful, but needs care. Clipboard API a better

1021
00:50:32.199 --> 00:50:33.320
<v Speaker 1>way to copy paste.

1022
00:50:33.400 --> 00:50:37.320
<v Speaker 2>Navigator dot Clipboard provides an async promise based API right

1023
00:50:37.880 --> 00:50:41.119
<v Speaker 2>text read text write for more complex data like images

1024
00:50:41.159 --> 00:50:44.360
<v Speaker 2>using clipboard item objects read. It's generally more secure as

1025
00:50:44.360 --> 00:50:48.159
<v Speaker 2>it often requires user permission, especially for reading. Also integrates

1026
00:50:48.159 --> 00:50:49.320
<v Speaker 2>with the copycut.

1027
00:50:48.880 --> 00:50:52.960
<v Speaker 1>Paste events, asynchronous and permission based sounds. Safer cross context

1028
00:50:52.960 --> 00:50:54.719
<v Speaker 1>messaging post message.

1029
00:50:54.360 --> 00:50:58.400
<v Speaker 2>Window dot post message message target origin allows safe communication

1030
00:50:58.480 --> 00:51:01.599
<v Speaker 2>between different windows I frame are workers, even if they're

1031
00:51:01.639 --> 00:51:06.039
<v Speaker 2>from different origins. The sender specifies the target origin for security,

1032
00:51:06.480 --> 00:51:09.320
<v Speaker 2>The receiver listens for the message, event checks event dot

1033
00:51:09.360 --> 00:51:12.239
<v Speaker 2>origin to verify the sender, and accesses the data via

1034
00:51:12.280 --> 00:51:16.320
<v Speaker 2>event dot data crucial for secure cross domain communication and

1035
00:51:16.360 --> 00:51:17.559
<v Speaker 2>things like embedded widgets.

1036
00:51:17.559 --> 00:51:21.719
<v Speaker 1>It's your window to Window Talk encoding API. Text encoder,

1037
00:51:21.880 --> 00:51:23.159
<v Speaker 1>text decoder.

1038
00:51:23.159 --> 00:51:26.880
<v Speaker 2>Simple but essential. Textingcoder converts a JavaScript string into a

1039
00:51:26.960 --> 00:51:29.800
<v Speaker 2>U and data array of UTFA bytes by default. Text

1040
00:51:30.039 --> 00:51:33.199
<v Speaker 2>cooder decoder, dot decode uit data array converts an array

1041
00:51:33.199 --> 00:51:36.199
<v Speaker 2>of bytes back into a JavaScript string. Handling different encodings

1042
00:51:36.400 --> 00:51:38.840
<v Speaker 2>useful when dealing with binary data from files or network

1043
00:51:38.840 --> 00:51:40.280
<v Speaker 2>requests that represents.

1044
00:51:39.800 --> 00:51:43.880
<v Speaker 1>Text, handling texting codings properly. Blob and file APIs for

1045
00:51:44.000 --> 00:51:45.239
<v Speaker 1>raw data and filed.

1046
00:51:45.159 --> 00:51:48.400
<v Speaker 2>Blob represents immutable raw data like a junk of binary data.

1047
00:51:48.559 --> 00:51:53.280
<v Speaker 2>File inherits from blob and adds file specific metadata like name, size, type,

1048
00:51:53.519 --> 00:51:55.880
<v Speaker 2>last modified usually comes from an input type file or

1049
00:51:55.960 --> 00:51:58.599
<v Speaker 2>drag and drop file reader reads the contents of blobs

1050
00:51:58.639 --> 00:52:01.679
<v Speaker 2>files asynchronously to text read as air buffer read as

1051
00:52:01.719 --> 00:52:05.440
<v Speaker 2>dator RRL. With events like onload on air. You can

1052
00:52:05.480 --> 00:52:10.000
<v Speaker 2>create object URLs url dot create creature l blob for

1053
00:52:10.079 --> 00:52:13.320
<v Speaker 2>referencing blobs files directly in things like MMG tags, but

1054
00:52:13.400 --> 00:52:16.039
<v Speaker 2>remember to URL revoke objet url when done.

1055
00:52:16.159 --> 00:52:19.760
<v Speaker 1>Comprehensive file handling. Full screen API making things take over

1056
00:52:19.800 --> 00:52:20.199
<v Speaker 1>the screen.

1057
00:52:20.440 --> 00:52:23.119
<v Speaker 2>Element dot request full screen ask the browser to make

1058
00:52:23.119 --> 00:52:26.800
<v Speaker 2>an element full screen requires user gesture usually document dot

1059
00:52:26.800 --> 00:52:29.320
<v Speaker 2>a inst full screen to leave document dot full screen.

1060
00:52:29.360 --> 00:52:31.760
<v Speaker 2>Element tells you what's full screen full screen change event

1061
00:52:31.800 --> 00:52:35.840
<v Speaker 2>fires when state changes. Good for videos, games, presentations.

1062
00:52:35.320 --> 00:52:39.360
<v Speaker 1>Immersive experiences. Geolocation API finding the user's.

1063
00:52:39.079 --> 00:52:43.880
<v Speaker 2>Location navigator dot geolocation methods get current positions success ab

1064
00:52:44.079 --> 00:52:48.039
<v Speaker 2>air CB options and watch position success CB air CB

1065
00:52:48.079 --> 00:52:52.079
<v Speaker 2>options needs user permission. Success callback gets a position object

1066
00:52:52.079 --> 00:52:56.400
<v Speaker 2>with chords latitude, longitude accuracy. Error callback gets position aer

1067
00:52:56.679 --> 00:53:01.039
<v Speaker 2>codes for permission denied, unavailable, timeout, use eaht TPS. Be

1068
00:53:01.159 --> 00:53:02.079
<v Speaker 2>mindful of privacy.

1069
00:53:02.119 --> 00:53:06.719
<v Speaker 1>Permission and privacy first. Other device APIs orientation network info.

1070
00:53:06.960 --> 00:53:09.880
<v Speaker 2>Yeah, we mentioned navigator dot connection for network details. Device

1071
00:53:09.920 --> 00:53:13.960
<v Speaker 2>orientation events. Device orientation, give alpha beta gamma values for

1072
00:53:14.000 --> 00:53:18.239
<v Speaker 2>physical orientation if hardware supported. Others like battery API are

1073
00:53:18.239 --> 00:53:21.079
<v Speaker 2>mostly deprecated. Provides context about the device environment.

1074
00:53:21.159 --> 00:53:24.199
<v Speaker 1>Good context fetch API the modern way for network.

1075
00:53:23.880 --> 00:53:27.920
<v Speaker 2>Requests absolutely fetch EARL options is the standard. Returns a

1076
00:53:27.920 --> 00:53:31.519
<v Speaker 2>promise that resolves to a response object. Options object controls

1077
00:53:31.559 --> 00:53:35.199
<v Speaker 2>method header's, body, credentials, cash, mode, et CETERA response object

1078
00:53:35.280 --> 00:53:38.119
<v Speaker 2>has methods to read the body response dot jason, response

1079
00:53:38.199 --> 00:53:41.280
<v Speaker 2>dot text, response dot, blob, response dot orra buffer. You

1080
00:53:41.400 --> 00:53:44.280
<v Speaker 2>check response dot OK or response dot status for success.

1081
00:53:44.719 --> 00:53:48.320
<v Speaker 2>Handle's cores via options and server headers. Integrates with request

1082
00:53:48.440 --> 00:53:51.199
<v Speaker 2>header's objects can be aborted using a board controller and

1083
00:53:51.239 --> 00:53:54.360
<v Speaker 2>a bort signal. Can work with dreams. Integrates with the cache.

1084
00:53:54.440 --> 00:53:59.719
<v Speaker 2>API caches for service workers. Far superior to XMLHTTP request.

1085
00:53:59.400 --> 00:54:02.440
<v Speaker 1>Fetch sounds like the complete package. Web sockets for real

1086
00:54:02.480 --> 00:54:03.360
<v Speaker 1>time communication.

1087
00:54:03.639 --> 00:54:06.400
<v Speaker 2>New web socket are established as a persistent two way connection.

1088
00:54:06.599 --> 00:54:10.559
<v Speaker 2>Ws dot, WS or WSS use eventhandlers dot on open

1089
00:54:10.639 --> 00:54:13.480
<v Speaker 2>on message gets data in event dot data on air

1090
00:54:13.559 --> 00:54:16.119
<v Speaker 2>on clothes send data with socket dot, send doses socket

1091
00:54:16.119 --> 00:54:19.400
<v Speaker 2>dot close. Great for chat, live updates, multiplayer games. Doesn't

1092
00:54:19.440 --> 00:54:21.840
<v Speaker 2>use ad event listener style. You assigned handlers.

1093
00:54:21.480 --> 00:54:26.079
<v Speaker 1>Directly persistent connections, web storage, local storage, session storage.

1094
00:54:25.800 --> 00:54:29.480
<v Speaker 2>Simple key value storage. In the browser. Local storage persists

1095
00:54:29.519 --> 00:54:32.960
<v Speaker 2>across browser sessions. Same origin. Session storage allows only for

1096
00:54:33.000 --> 00:54:36.039
<v Speaker 2>the current tab. Windows session both have set item key value,

1097
00:54:36.159 --> 00:54:39.199
<v Speaker 2>remove item key clear length limits around five to ten

1098
00:54:39.239 --> 00:54:41.519
<v Speaker 2>mil us storage event fires and other tabs. When storage

1099
00:54:41.639 --> 00:54:44.000
<v Speaker 2>changes stores values is strings.

1100
00:54:43.639 --> 00:54:44.880
<v Speaker 3>Simple key value stores.

1101
00:54:45.280 --> 00:54:47.760
<v Speaker 1>Then for more complex data, index dB.

1102
00:54:47.880 --> 00:54:51.239
<v Speaker 2>Yes INDEXTB is a full transactional NOSEQL database in the browser,

1103
00:54:51.679 --> 00:54:56.519
<v Speaker 2>stores complex JavaScript objects, files, blobs, asynchronous API. You work

1104
00:54:56.559 --> 00:55:00.960
<v Speaker 2>with databases object stores like tables, indexes for query transactions,

1105
00:55:01.000 --> 00:55:04.760
<v Speaker 2>cursors for iteration. Open with index dB open name version,

1106
00:55:05.039 --> 00:55:07.920
<v Speaker 2>schema changes happen in the unupgrade needed event powerful for

1107
00:55:07.960 --> 00:55:09.559
<v Speaker 2>offline apps and large data sets.

1108
00:55:09.599 --> 00:55:12.679
<v Speaker 1>A real database in the browser. Okay. Modules organizing code

1109
00:55:12.960 --> 00:55:15.199
<v Speaker 1>ES modules versus the old module pattern.

1110
00:55:15.400 --> 00:55:19.599
<v Speaker 2>Module pattern used iiv's enclosures to simulate modules. Es, modules,

1111
00:55:19.800 --> 00:55:23.159
<v Speaker 2>import exports, script type module are the native standard, much

1112
00:55:23.159 --> 00:55:27.960
<v Speaker 2>cleaner syntax, static analysis benefits, better dependency management. Named exports

1113
00:55:28.159 --> 00:55:31.360
<v Speaker 2>export x inport x, default exports, export default y, import y,

1114
00:55:31.519 --> 00:55:34.920
<v Speaker 2>dynamic import phrase incloading import maps for controlling resolution. The

1115
00:55:35.000 --> 00:55:36.159
<v Speaker 2>modern standard.

1116
00:55:35.880 --> 00:55:39.920
<v Speaker 1>Native modules are the way forward. Web workers background threads yes.

1117
00:55:40.000 --> 00:55:42.519
<v Speaker 2>Run jas off the main UI thread to avoid blocking

1118
00:55:42.800 --> 00:55:46.719
<v Speaker 2>dedicated workers. New worker for a single script, shared workers,

1119
00:55:46.760 --> 00:55:50.119
<v Speaker 2>new shared worker accessible by multiple scripts same origin. Service

1120
00:55:50.119 --> 00:55:53.239
<v Speaker 2>workers act as network proxies for offline support, push notifications,

1121
00:55:53.239 --> 00:55:56.800
<v Speaker 2>et cetera. Communicate via post message and on message. Data

1122
00:55:56.840 --> 00:56:00.960
<v Speaker 2>is copied, structured, cloning, or transfer transferable like a ray buffer.

1123
00:56:01.320 --> 00:56:03.320
<v Speaker 2>Each worker type has different scope in life cycle.

1124
00:56:03.639 --> 00:56:07.840
<v Speaker 1>Essential for performance parallelism in the browser. Important error handling

1125
00:56:07.840 --> 00:56:10.400
<v Speaker 1>and debugging stayingsane.

1126
00:56:10.119 --> 00:56:13.760
<v Speaker 2>Use try, dot, catch dot finally, throw errors with throw

1127
00:56:13.840 --> 00:56:16.800
<v Speaker 2>new error or specific types type er, et cetera. Handle

1128
00:56:16.880 --> 00:56:20.840
<v Speaker 2>global errors with window dot one, air, use browserdeb tools extensively,

1129
00:56:21.280 --> 00:56:26.840
<v Speaker 2>console debugger breakpoints, stepping, network panel, static analysis linters. Typescript

1130
00:56:27.079 --> 00:56:30.559
<v Speaker 2>helps catch errors early assertions can help during development. Robust

1131
00:56:30.639 --> 00:56:31.639
<v Speaker 2>error handling is key.

1132
00:56:31.840 --> 00:56:35.760
<v Speaker 1>Good practices are essential. Finally, json stringify.

1133
00:56:35.239 --> 00:56:39.639
<v Speaker 2>And parse Gson does stringify value. Replacer space converts a

1134
00:56:39.719 --> 00:56:43.840
<v Speaker 2>JS value to a JSON string. Json Dot parse text

1135
00:56:43.880 --> 00:56:47.159
<v Speaker 2>Reviver parses a Jason string back into a JS value.

1136
00:56:47.599 --> 00:56:52.039
<v Speaker 2>Replacer and reviver functions allow customization during serialization de serialization.

1137
00:56:52.480 --> 00:56:56.119
<v Speaker 2>Space argument pritifies the string output ubiquitous for data exchange,

1138
00:56:56.199 --> 00:56:58.119
<v Speaker 2>especially with apisvia.

1139
00:56:57.440 --> 00:57:00.760
<v Speaker 1>Fetch perfect, and we covered fetch for the actual sending earlier.

1140
00:57:00.880 --> 00:57:03.519
<v Speaker 2>Yep fetches how you typically get that Jason data from

1141
00:57:03.519 --> 00:57:03.840
<v Speaker 2>a server?

1142
00:57:04.000 --> 00:57:07.440
<v Speaker 1>Wo Okay. That was a seriously deep dive into JavaScript

1143
00:57:07.480 --> 00:57:10.159
<v Speaker 1>and the web platform. It's a massive ecosystem.

1144
00:57:10.320 --> 00:57:12.360
<v Speaker 2>It really is so many layers, from the core language

1145
00:57:12.360 --> 00:57:16.280
<v Speaker 2>features to these incredibly powerful browser APIs, and they all interconnect.

1146
00:57:16.440 --> 00:57:19.639
<v Speaker 1>Yeah, hopefully this gives you, our listener, a really solid

1147
00:57:19.679 --> 00:57:23.280
<v Speaker 1>map of the territory, a framework for understanding how all

1148
00:57:23.320 --> 00:57:26.440
<v Speaker 1>these pieces fit together in modern web development.

1149
00:57:26.639 --> 00:57:29.000
<v Speaker 2>It's definitely a foundation you can build on whether you're

1150
00:57:29.000 --> 00:57:31.920
<v Speaker 2>focusing on say React or view or maybe no JS

1151
00:57:31.960 --> 00:57:35.159
<v Speaker 2>on the back end, or getting deep into specific APIs

1152
00:57:35.199 --> 00:57:36.559
<v Speaker 2>like WebGL or web RTC.

1153
00:57:36.760 --> 00:57:38.880
<v Speaker 1>And it just keeps changing, doesn't it. JavaScript and the

1154
00:57:38.880 --> 00:57:40.599
<v Speaker 1>web platform are constantly evolving.

1155
00:57:40.639 --> 00:57:43.320
<v Speaker 2>They really are. Which leads to a final thought, maybe,

1156
00:57:43.840 --> 00:57:47.119
<v Speaker 2>given everything we've touched on today, this huge landscape, what's

1157
00:57:47.159 --> 00:57:49.800
<v Speaker 2>the one area of JavaScript or the web platform that

1158
00:57:49.880 --> 00:57:51.639
<v Speaker 2>really sparks your curiosity right now?

1159
00:57:51.719 --> 00:57:53.880
<v Speaker 1>That's a great question for everyone listening to think about,

1160
00:57:54.199 --> 00:57:57.320
<v Speaker 1>where do you want to explore next? Keep learning, keep building.

1161
00:57:57.480 --> 00:57:59.000
<v Speaker 1>Thanks for joining us on the deep Dive
