Latest / CyberSecurity Summary / Professional JavaScript for Web Developers
Transcript
- 0:00Speaker 1: Welcome to the deep dive. Think of this as your
- 0:03Speaker 1: cheat sheet, maybe your shortcut to getting really well informed
- 0:05Speaker 1: about important stuff.
- 0:07Speaker 2: Yeah, we basically wade through all the information, find the
- 0:09Speaker 2: core ideas, and bring back what you really need to know.
- 0:12Speaker 3: Saves you time exactly.
- 0:14Speaker 1: And today we are plunging into javascripts specifically for web developers.
- 0:19Speaker 1: We've got a whole stack of resources here.
- 0:22Speaker 2: We do, covering well everything from the real basic building
- 0:26Speaker 2: blocks right up to the you know, the fancy new
- 0:28Speaker 2: browser APIs and features just emerging.
- 0:30Speaker 1: Right, So the mission for this deep dive pull out
- 0:34Speaker 1: the essential concepts, maybe some surprising details about modern JS development.
- 0:38Speaker 2: Give you a solid handle on it without you know,
- 0:41Speaker 2: drowning you in every single tiny detail.
- 0:43Speaker 1: Perfect. Okay, let's kick things off with something well fundamental.
- 0:47Speaker 1: We always hear javascripts and ECMAScript toss around. What's the
- 0:50Speaker 1: actual relationship there?
- 0:52Speaker 2: Okay, good starting point. Think of ECMAScript as the official standard.
- 0:56Speaker 2: It's the specificating like the rule book for how a
- 0:59Speaker 2: scripting language should behave the rulebook okay in JavaScript? Well,
- 1:03Speaker 2: JavaScript is the most well known language that actually follows
- 1:06Speaker 2: those rules. It implements the ECMAScript standard.
- 1:09Speaker 1: Ah, got it? So xmascript is the spec. JavaScript is
- 1:12Speaker 1: the implementation.
- 1:14Speaker 2: Exactly, and just like languages evolve, xmascript gets updated, new editions,
- 1:19Speaker 2: come out S six, S twenty twenty, whatever, adding new features,
- 1:22Speaker 2: refining things. JavaScript then usually catches up and implements those
- 1:26Speaker 2: new features.
- 1:26Speaker 1: Makes sense. So when we put JavaScript on a web page,
- 1:30Speaker 1: we use the script tags. Our sources mentioned two main
- 1:32Speaker 1: types these days, the old text JavaScript and the newer module.
- 1:36Speaker 2: What's the key difference, right, So script type text JavaScript,
- 1:40Speaker 2: that's the classic way. Code inside there runs in well
- 1:43Speaker 2: basically the global scope for that script.
- 1:44Speaker 1: Everything together pretty much.
- 1:46Speaker 2: But script type module is different. I came with EES six.
- 1:48Speaker 2: It tells the browser, hey, treat this code as a
- 1:51Speaker 2: proper ECMAScript.
- 1:52Speaker 1: Module and what does that let us do?
- 1:54Speaker 2: That unlocks features like import and export, so you can
- 1:56Speaker 2: break your code into smaller, reusable pieces, manage dependence the cleanly.
- 2:00Speaker 2: It's a huge step up for organization and avoiding conflicts.
- 2:03Speaker 1: Right, So it stops everything from just clashing in that
- 2:05Speaker 1: one big global space, more organized, way, more organized.
- 2:09Speaker 2: With separate offices communicating properly instead of one giant noisy room.
- 2:13Speaker 1: Good analogy. Okay, moving into the code itself, comments, essential notes.
- 2:18Speaker 2: Right.
- 2:19Speaker 1: Our sources mentioned the C style comments.
- 2:22Speaker 2: Yep, JavaScript uses the familiar SEA style you've got for
- 2:25Speaker 2: single line comments. Anything after that on the line is ignored.
- 2:28Speaker 1: And the multi line ones that's.
- 2:29Speaker 2: To start and to end. You can put multiple lines
- 2:31Speaker 2: of comments between those. It was a natural fit really,
- 2:34Speaker 2: given JavaScript's influences and how common C style syntax was.
- 2:38Speaker 1: Makes sense. Keep it familiar. Now, code structure curly braces.
- 2:42Speaker 1: We use them everywhere, like with if statements. Are they
- 2:45Speaker 1: just for looks or more fundamental?
- 2:47Speaker 2: Oh, they're fundamental. They define code blocks. You can technically
- 2:50Speaker 2: omit them for a single statement after an IF or
- 2:53Speaker 2: a four like if condition do one thing.
- 2:56Speaker 3: Yeah, I've seen that, but it's really.
- 2:58Speaker 2: Really considered best practiced. Always use the curly braces. It
- 3:01Speaker 2: makes the code much easier to read and prevents subtle
- 3:04Speaker 2: bugs later if you add more statements to that block.
- 3:07Speaker 1: Good advice, Always use the braces. Okay, Variables the heart
- 3:12Speaker 1: of storing data. We've got the old var and the
- 3:15Speaker 1: newer let and constant. Let's break down the key differences,
- 3:18Speaker 1: scope hoisting all that stuff.
- 3:21Speaker 2: Right, So var it's function scoped, meaning if you declare
- 3:25Speaker 2: a var inside a function, it's known throughout that entire function,
- 3:29Speaker 2: even inside nested blocks like ifts or loops.
- 3:32Speaker 1: Okay, function scope and hoisting.
- 3:34Speaker 2: Ye, var declarations are hoisted. That means the declaration part
- 3:38Speaker 2: like varx is conceptually moved to the top of its
- 3:40Speaker 2: function scope.
- 3:41Speaker 1: Before the code runs just the declaration.
- 3:43Speaker 2: Just the declaration the assignment x equals ten stays where
- 3:46Speaker 2: you wrote it. This can lead to weird situations where
- 3:49Speaker 2: you can use a variable before its declaration appears in
- 3:51Speaker 2: the code, and it'll have the value undefined.
- 3:54Speaker 1: And you can readeclare var variables too.
- 3:56Speaker 2: Yep, you can write var myvar five and then later
- 3:59Speaker 2: varivar ten in the same scope and JavaScript is fine
- 4:02Speaker 2: with it, which can also cause confusion.
- 4:03Speaker 1: Definitely sounds like it could. So how does let improve things?
- 4:07Speaker 2: Let was introduced in e S six to fix these issues.
- 4:10Speaker 2: The big change is block scope. A LET variable is
- 4:12Speaker 2: only known within the specific block that curly braces words.
- 4:15Speaker 1: Defined, So inside an if or a for loop, it
- 4:18Speaker 1: only exists there exactly.
- 4:20Speaker 2: Much more contained, much easier to reason about. It prevents
- 4:23Speaker 2: accidental variable clashes between different parts of your code.
- 4:26Speaker 1: That sounds way better. What about hoisting and redeclaration with let.
- 4:30Speaker 2: Let declarations are also hoisted, but critically their initialization is not.
- 4:35Speaker 2: This creates something called the temporal dead zone or TDZ.
- 4:38Speaker 2: If you try to access a let variable before it's
- 4:40Speaker 2: actual declaration line in the code, you get a reference there.
- 4:43Speaker 1: Ah. Okay, so safer prevents using it before it's.
- 4:46Speaker 2: Ready, right, and you cannot redeclare a let variable within
- 4:49Speaker 2: the same scope. Yeah, if you try let x five
- 4:52Speaker 2: let x bleeds ten in the same block, you'll get
- 4:55Speaker 2: an error much stricter.
- 4:56Speaker 1: Good and then const the name implies it can't be changed.
- 5:00Speaker 2: Very similar to it's also block scoped has the TDZ
- 5:03Speaker 2: and cannot be redeclared in the same scope.
- 5:05Speaker 1: But the key difference.
- 5:07Speaker 2: You must initialize a cost variable when you declare it
- 5:10Speaker 2: like cost pi equals three point one four, and once assigned,
- 5:14Speaker 2: you cannot reassign that variable to a different value. The
- 5:17Speaker 2: binding is constant.
- 5:19Speaker 1: So pi equals three later would cause an error exactly.
- 5:23Speaker 2: But and this is important, if the const variable holds
- 5:26Speaker 2: an object or an array, you could still change the
- 5:29Speaker 2: contents of that object or array. You just can't make
- 5:31Speaker 2: the variable point to a completely new object or array.
- 5:34Speaker 1: Ah. Subtle but crucial distinctions. The variable binding is constant,
- 5:38Speaker 1: not necessarily the value itself if it's an object precisely.
- 5:42Speaker 2: And our sources mentioned a potential performance benefit to using
- 5:45Speaker 2: let and const over var, because the engine has a
- 5:48Speaker 2: better idea of how the variable will be used.
- 5:50Speaker 1: Interesting worth keeping in mind. Now, naming these variables identifiers,
- 5:53Speaker 1: are there strict rules?
- 5:55Speaker 2: Yes, identifiers have to start with a letter, an underscore,
- 5:58Speaker 2: or a dollar sign after the first character. You can
- 6:00Speaker 2: also use numbers, okay.
- 6:02Speaker 1: Any things you can't use definitely.
- 6:04Speaker 2: You can't use JavaScript keywords like if, for function, let, const, var,
- 6:09Speaker 2: et cetera. You also can't use reserved words words set
- 6:12Speaker 2: aside for future use, and the literal values true, false,
- 6:16Speaker 2: and null are also off limits as variable names.
- 6:19Speaker 1: Makes sense, don't want to confuse the language itself. Okay,
- 6:22Speaker 1: Let's talk data types the primitives first. These are the
- 6:24Speaker 1: simple fundamental types, right, the.
- 6:27Speaker 2: Basic building blocks. First up is number. This covers both
- 6:30Speaker 2: integers and floating point numbers. JavaScript doesn't really distinguish between
- 6:34Speaker 2: them internally in the way some other languages do.
- 6:36Speaker 1: Some number okay, Any special ways to write.
- 6:39Speaker 2: Numbers, Yeah, you can write integers in decimal obviously, but
- 6:42Speaker 2: also binary using a zero B prefix, octal with a
- 6:45Speaker 2: zero O prefix or just eleading zero in nonstrict mode,
- 6:48Speaker 2: which can be confusing, and hexadecimal with zero.
- 6:52Speaker 1: X hex is pretty common in web dev, very common.
- 6:55Speaker 2: And within number you also have the special values nan
- 6:58Speaker 2: not a.
- 6:59Speaker 1: Number, which can confusingly is a number type right?
- 7:01Speaker 2: Ah? Yes, type of nan returns number. It usually results
- 7:04Speaker 2: from invalid math operations like zero zero, and you have
- 7:07Speaker 2: infinity and into infinity.
- 7:09Speaker 1: Okay, And what about really really huge numbers.
- 7:12Speaker 2: That's where bigin comes in. It's a newer primitive type
- 7:15Speaker 2: designed to handle integers larger than the maximum safe integer
- 7:19Speaker 2: value for number, which is around two to the power
- 7:22Speaker 2: of fifty three minus one.
- 7:23Speaker 3: Wow.
- 7:24Speaker 1: How do you create those?
- 7:25Speaker 2: You append an end to the end of an integer
- 7:27Speaker 2: literal like one, two, three, four five n or you
- 7:30Speaker 2: use the big in function.
- 7:31Speaker 1: Any gotcha's with big inn.
- 7:33Speaker 2: Yeah. You can't mix biggest and number types in standard
- 7:36Speaker 2: arithmetic operations directly. You have to convert them, and you
- 7:38Speaker 2: can't use big in values with the built in math
- 7:41Speaker 2: object methods.
- 7:42Speaker 1: Good to know. Okay. Beyond numbers, we have.
- 7:44Speaker 2: String represents text basically a sequence of sixteen bit Unicode characters.
- 7:49Speaker 2: You can use single quotes, double quotes, or backticks to
- 7:53Speaker 2: define them.
- 7:53Speaker 1: Any difference between single and double quotes.
- 7:56Speaker 2: Functionally no, it's mostly style preference, though enable template literals,
- 8:02Speaker 2: which are super useful for embetting expressions directly into strings.
- 8:05Speaker 1: Right with the syntax very handy.
- 8:07Speaker 2: Next, boolean simple one can only be true or false,
- 8:10Speaker 2: used all the time for conditional logic.
- 8:12Speaker 1: Okay, and then null and undefined They seem similar but
- 8:16Speaker 1: aren't quite.
- 8:17Speaker 2: The same correct. Null is a primitive type that represents
- 8:21Speaker 2: the intentional absence of any object value you explicitly set
- 8:25Speaker 2: something to null. Undefined means a variable has been declared
- 8:29Speaker 2: but hasn't been assigned of value yet. It's the default state.
- 8:33Speaker 1: So null is I meant for this to be empty?
- 8:35Speaker 1: And undefined is nobody put anything here yet?
- 8:38Speaker 2: That's a good way to think about it. And finally,
- 8:40Speaker 2: among the primatives, there's symbol symbols.
- 8:43Speaker 1: These are unique identifiers right exactly.
- 8:45Speaker 2: Symbol creates a unique, immutable primitive value. Even if you
- 8:50Speaker 2: create two symbols with the same description, like symbol foo
- 8:52Speaker 2: and simple foo, they are not equal. They're unique.
- 8:55Speaker 1: What are they used for?
- 8:56Speaker 2: Often? Uses keys for object properties when you want to
- 8:59Speaker 2: avoid potential clashes with other properties or library code. There's
- 9:03Speaker 2: also symbol dot four key, which creates or retrieve symbols
- 9:06Speaker 2: from a global registry. So symbol dot for food.
- 9:10Speaker 1: Interesting. Do they show up in normal object iteration? Not?
- 9:13Speaker 2: Usually they aren't enumerated by four dot. In loops, you
- 9:16Speaker 2: need specific methods like object dot get town property symbols,
- 9:19Speaker 2: or reflect dot own keys to access them.
- 9:21Speaker 1: Okay, and there are built in symbols.
- 9:23Speaker 2: Too, Yes, well known symbols like symbol dot iterator, symbol
- 9:26Speaker 2: dot replace, symbol dot search. These allow you to hook
- 9:29Speaker 2: into fundamental language behaviors.
- 9:31Speaker 1: That's a lot of primitives. Okay, let's talk operators doing
- 9:35Speaker 1: things with these values basic math like and seem straightforward.
- 9:39Speaker 1: But what about those bitwise operators? When do we use those?
- 9:43Speaker 2: Right? So, multiplication and division have rules for nan and
- 9:45Speaker 2: infinity like infinity zeros in NAN, but the bitwise operators
- 9:49Speaker 2: and D or xo R not marriot left shift signed
- 9:53Speaker 2: right shift, unsigned right shift. They operate directly on the
- 9:56Speaker 2: binary representation of numbers.
- 9:58Speaker 1: Lower level stuff, yeah.
- 9:59Speaker 2: Very low level. You might use them for things like
- 10:01Speaker 2: manipulating flags stored in a single number. Performance critical calculations,
- 10:05Speaker 2: maybe graphics or network protocol work where you're packing data efficiently.
- 10:09Speaker 1: So left shift multiplies by powers of two.
- 10:12Speaker 2: Correct and preserves the sign signed right shift divides by
- 10:15Speaker 2: powers of two, also preserving the sign. Unsigned right shifts
- 10:18Speaker 2: also divides, but always fills with zeros on the left,
- 10:20Speaker 2: so the result is always non negative. Not everyday tools
- 10:24Speaker 2: for most web devs, but good to know they.
- 10:26Speaker 1: Exist definitely now the sources mentioned the with statement sounds old, it.
- 10:30Speaker 2: Is and definitely deprecated and forbidden in strict mode. Its
- 10:34Speaker 2: idea was to shorten access to object properties like with
- 10:38Speaker 2: document dot location instead of repeating document dot location.
- 10:43Speaker 1: Why is it bad?
- 10:44Speaker 2: It makes code really hard to understand because it's unclear
- 10:46Speaker 2: where variables are coming from. Are they local, global, or
- 10:50Speaker 2: from the with object And it kills performance because the
- 10:53Speaker 2: engine can't easily optimize lookups.
- 10:55Speaker 1: Avoid it good advice avoid with Okay, last fundamental strict
- 11:00Speaker 1: mode you strict. Why should we use this?
- 11:02Speaker 2: Strict mode is basically a way to opt into a cleaner, safer,
- 11:06Speaker 2: less error prone version of JavaScript. You put the string
- 11:09Speaker 2: you strict at the very top of a script or
- 11:11Speaker 2: a function, and what does it do. It changes certain things.
- 11:14Speaker 2: It turned some previously silent errors into throne errors. For example,
- 11:18Speaker 2: assigning a value to an undeclared variable throws an error
- 11:21Speaker 2: instead of implicitly creating a global variable.
- 11:23Speaker 1: Ah. That's good. Helps catch typos exactly.
- 11:26Speaker 2: It also prevents or throws errors for certain unsafe actions
- 11:30Speaker 2: like deleting variables or functions. It bans the wis statement.
- 11:35Speaker 2: It makes evil safer. It prevents using reserved words like
- 11:38Speaker 2: evil or arguments as variable names.
- 11:41Speaker 1: So it basically tightens up the rules and catches common
- 11:43Speaker 1: mistakes pretty much.
- 11:45Speaker 2: It helps you write more robust, maintainable code. It's highly
- 11:48Speaker 2: recommended for all modern JavaScript development.
- 11:50Speaker 1: Makes total sense like built in code review. Okay, let's
- 11:53Speaker 1: switch gears to objects in a raise complex data first.
- 11:57Speaker 1: That distinction primitive versus reference value. Why is this so critical?
- 12:02Speaker 2: It fundamentally changes how you work with data. Primitive values, numbers, strings, booleans,
- 12:08Speaker 2: et cetera. Are passed by value. When you assign a
- 12:10Speaker 2: primitive variable to another, you're making a completely separate.
- 12:13Speaker 1: Copy, independent copies, right.
- 12:15Speaker 2: But reference values objects in a raise are passed by reference.
- 12:18Speaker 2: When you assign an object variable to another, both variables
- 12:22Speaker 2: end up pointing to the exact same object in memory.
- 12:24Speaker 1: So changing the object through one variable affects the other absolutely.
- 12:28Speaker 2: If you have OBJ one down a OBJ two dot
- 12:30Speaker 2: day one and then you do OBJ two dot name
- 12:32Speaker 2: aples a b UPJ one dot name will also be b.
- 12:35Speaker 2: They're referencing the same underlying data structure. Understanding this is
- 12:37Speaker 2: crucial for avoiding unexpected side effects.
- 12:40Speaker 1: Definitely okay, So how do we figure out what type
- 12:43Speaker 1: of data we have? Type of seems like the obvious choice,
- 12:46Speaker 1: but it has quirks.
- 12:47Speaker 2: It does type or for works great for primitives number, string,
- 12:52Speaker 2: boolly and undefined symbol big int. It also correctly identifies
- 12:57Speaker 2: functions returning function.
- 12:58Speaker 1: But for objects, and as for.
- 13:00Speaker 2: Most reference types, including regular objects in arrays, type offf
- 13:04Speaker 2: just returns object, and confusingly, type of null also returns object.
- 13:08Speaker 2: That's a long standing historical bug.
- 13:10Speaker 1: So type of isn't always specific enough for objects. What
- 13:12Speaker 1: else can we use?
- 13:13Speaker 2: The instance of operator is often better for checking object types.
- 13:16Speaker 2: You can do my array instance of array or my
- 13:19Speaker 2: date instance of date to see if an object was
- 13:21Speaker 2: created by a specific constructor or inherits from its prototype.
- 13:24Speaker 1: Okay, instance of for more specific object checks now scope.
- 13:28Speaker 1: How does JavaScript know which variable we mean when we
- 13:30Speaker 1: use a name? The scope chain exactly.
- 13:33Speaker 2: Scope determines where variables are accessible. JavaScript uses lexical scope,
- 13:38Speaker 2: meaning scope is defined by where the code is physically written.
- 13:41Speaker 2: When you use a variable, the engine first looks in
- 13:44Speaker 2: the current innermost scope, and if it's not there, looks
- 13:47Speaker 2: in the next scope outwards, then the next, and so
- 13:49Speaker 2: on up the chain until it hits the global scope.
- 13:53Speaker 2: This sequence of scopes is the.
- 13:56Speaker 3: Scope chain, like nested boxes pretty much.
- 13:59Speaker 2: If it which is the global scope and still doesn't
- 14:01Speaker 2: find the variable, you get a reference error in strict mode. Anyway,
- 14:05Speaker 2: looking up globals can be slightly slower than locals because
- 14:07Speaker 2: the chain might be longer, but engines optimize this well.
- 14:11Speaker 1: Okay. And memory management, JavaScript cleans up after itself with
- 14:15Speaker 1: garbage collection. How does that work?
- 14:17Speaker 2: Yes? JavaScript has automatic garbage collection PC. The engine tracks
- 14:21Speaker 2: which objects are still reachable, meaning they can somehow be accessed,
- 14:24Speaker 2: starting from the root objects like the global.
- 14:27Speaker 1: Window object, so it traces all the references kind of.
- 14:30Speaker 2: The most common algorithm is mark and sweep. The GC
- 14:34Speaker 2: starts at the roots, marks all reachable objects, and then
- 14:37Speaker 2: sweeps through memory reclaiming the memory used by any object
- 14:41Speaker 2: that wasn't marked.
- 14:42Speaker 1: So if nothing points to an object anymore, it gets
- 14:44Speaker 1: swept up.
- 14:45Speaker 2: Essentially, Yes, it's automatic, but not fool proof. You can
- 14:50Speaker 2: still create memory leaks if you unintentionally keep references to
- 14:53Speaker 2: objects you no longer need. And the timing of GC
- 14:56Speaker 2: is nondeterministic. You don't control exactly when it runs.
- 15:00Speaker 1: I know it's mostly handled, but leaks are still possible.
- 15:02Speaker 1: All right, let's look at specific reference types. The basic object.
- 15:05Speaker 1: It's more than just key value pairs, isn't it.
- 15:07Speaker 2: Oh yeah. Object is the foundation for almost everything complex
- 15:11Speaker 2: in JavaScript. It's a dynamic collection of properties where keys
- 15:14Speaker 2: are usually strings or symbols, and values can be anything.
- 15:17Speaker 2: We usually create them with object literals. It's the basis
- 15:20Speaker 2: for prototype based inheritance, which is core to JS.
- 15:24Speaker 1: The cornerstone, okay, an array. It's like a list, but
- 15:27Speaker 1: more flexible than in some languages.
- 15:29Speaker 2: Definitely. JavaScript arrays are ordered lists, but they're dynamic. They
- 15:33Speaker 2: can grow and shrink, and importantly, they can hold elements
- 15:36Speaker 2: of any data type mixed together. A single ray could
- 15:38Speaker 2: have numbers, strings, objects, even other.
- 15:41Speaker 3: Arrays very flexible.
- 15:43Speaker 1: How do we make arrays. Literals are common.
- 15:45Speaker 2: Literals are the most common and usually the best way.
- 15:48Speaker 2: You can also use new array, but it has some
- 15:49Speaker 2: weird behavior if you pass just one number argument. A
- 15:53Speaker 2: ray out from is super useful for converting array like
- 15:56Speaker 2: things like dom modalists or the argument's object or iter
- 16:00Speaker 2: like sets or maps into real arrays.
- 16:02Speaker 1: Array dot from some sandy and array dot from.
- 16:05Speaker 2: Array does creates a new array with whatever arguments you
- 16:08Speaker 2: pass it. A ray dot one two three gives one
- 16:10Speaker 2: two three, and a ray of seven gives seven. It
- 16:12Speaker 2: avoids the new array seven confusion, which creates an mpty
- 16:14Speaker 2: array of length seven.
- 16:15Speaker 1: Got it now changing array contents, dot fil sort, splice,
- 16:21Speaker 1: What do these do?
- 16:21Speaker 2: Phil Let's you set all or part of an array
- 16:23Speaker 2: to a static value. Useful for initialization. Sort sorts the
- 16:27Speaker 2: array in place than gotcha. By default, it sorts lexicographically
- 16:31Speaker 2: like stringths.
- 16:32Speaker 1: So one ten two would sort to one ten two exactly.
- 16:35Speaker 2: For numeric sorting, you must provide a comparison function like
- 16:38Speaker 2: ab equal ab for ascending order.
- 16:41Speaker 1: Right always provide the compare function for numbers, and splice.
- 16:44Speaker 2: Splice is the Swiss army knife. Let's remove elements in
- 16:46Speaker 2: some elements or replace elements all of a specific index,
- 16:49Speaker 2: modifying the original array directly. It's very powerful. Splice in
- 16:53Speaker 2: x lead count outum one item.
- 16:54Speaker 1: Two okay, modifies in place. What about finding things? Index
- 16:58Speaker 1: of last and x xen inclusion.
- 17:00Speaker 2: The first index of an item searching forwards last index
- 17:02Speaker 2: yeah finds the last index searching backwards. Both return to
- 17:05Speaker 2: nus one if not found, and both use strict equality
- 17:07Speaker 2: and include just returns true or if false if the item
- 17:10Speaker 2: exists in the array. Simpler if you don't need the index.
- 17:12Speaker 2: It also uses strict equality index of and last index.
- 17:15Speaker 2: Oves can take an optional second argument for the starting
- 17:18Speaker 2: search position.
- 17:19Speaker 1: Use includes for existence, check indexoflast, index of if you
- 17:24Speaker 1: need the position. And reduce sounds like it boils an
- 17:27Speaker 1: array down.
- 17:28Speaker 2: It does. Reduce iterates through an array applying a function
- 17:31Speaker 2: you provide to accumulate a single result. The function gets
- 17:34Speaker 2: the accumulator, the current value, the index, and the array itself.
- 17:37Speaker 2: You can some numbers, build an object, flatten an array
- 17:41Speaker 2: really versatile. You usually provide an initial value for the accumulator.
- 17:45Speaker 1: Powerful stuff, okay. Type dearrays in eight array float thirty
- 17:49Speaker 1: two array. These sound specialized? Why use them over regular arrays.
- 17:53Speaker 2: Performance, mainly when dealing with raw binary data. Regular rays
- 17:57Speaker 2: are super flexible, but that flexibility has overhead. Type raise
- 18:01Speaker 2: give you a direct fixed length view onto a chunk
- 18:03Speaker 2: of binary memory an array buffer, where each element is
- 18:07Speaker 2: known to be a specific numeric type like eight bit unsigned, editger,
- 18:10Speaker 2: thirty two bit float, et cetera.
- 18:12Speaker 1: So for things like graphics or processing audio data.
- 18:15Speaker 2: Exactly WebGL web audio API manipulating file data read into
- 18:20Speaker 2: an array buffer. They share many methods with regular arrays,
- 18:23Speaker 2: map filter, etc. But they operate within the constraints of
- 18:25Speaker 2: their type and fixed length. They also have methods like
- 18:28Speaker 2: set for efficiently copying data in and subaray to create
- 18:32Speaker 2: a new typed to array view over a portion of
- 18:33Speaker 2: the same buffer.
- 18:34Speaker 1: Efficient binary data handling and data view. How's that different?
- 18:39Speaker 2: Data View also works on an array buffer, but it's
- 18:41Speaker 2: even lower level. Instead of viewing the whole buffer as
- 18:44Speaker 2: one type, data view lets you read and write different
- 18:47Speaker 2: numeric types at any byte offset within the buffer.
- 18:50Speaker 1: So you could read an eight bit in then a
- 18:52Speaker 1: sixteen bit float from the same.
- 18:54Speaker 2: Buffer precisely, and crucially, data view lets you control the
- 18:57Speaker 2: endianness byte order big indian or little endian for multi
- 19:01Speaker 2: byte types. This is essential when you're working with specific
- 19:04Speaker 2: file formats or network protocols that dictate a particular byte order.
- 19:08Speaker 1: So typed arrays for uniform numeric arrays. Data view for
- 19:13Speaker 1: fine grained multi type endingess controlled access to binary data.
- 19:17Speaker 2: That's a great summary.
- 19:18Speaker 1: Okay, let's talk collections, map and set. How are they
- 19:21Speaker 1: different from plain objects and arrays.
- 19:23Speaker 2: Map is like an object for key value pairs, but
- 19:25Speaker 2: with key differences. Keys in a map can be any
- 19:28Speaker 2: data type, not just strings or symbols. You can use
- 19:31Speaker 2: an object or even a function as a key. Also,
- 19:33Speaker 2: map remembers the original insertion order.
- 19:35Speaker 1: Of keys any data type as a key and ordered
- 19:38Speaker 1: useful and set.
- 19:40Speaker 2: Set is a collection of unique values you add items,
- 19:43Speaker 2: and duplicates are automatically ignored. Like MAP, it also remembers
- 19:47Speaker 2: insertion order. Great for quickly removing duplicates from an array
- 19:51Speaker 2: or just storing a list where uniqueness matters.
- 19:53Speaker 1: Set for uniqueness map for flexible keys. What about weak set?
- 19:57Speaker 1: What's weak about it?
- 19:59Speaker 2: Weekset is it's like set, but it only holds objects,
- 20:02Speaker 2: and it holds them weekly. This means if an object
- 20:05Speaker 2: is only referenced by the weakset and nowhere else in
- 20:07Speaker 2: your code. The garbage collector is free to remove it.
- 20:10Speaker 1: Ah, so it doesn't prevent garbage collection. Why is that useful?
- 20:13Speaker 2: It's great for associating metadata with objects without preventing those
- 20:16Speaker 2: objects from being cleaned up if they're removed from say
- 20:20Speaker 2: the DOM. If you remove a DOM element and it
- 20:22Speaker 2: was in the week set, the weekset reference won't keep
- 20:25Speaker 2: it lingering in memory because items can disappear. You can't
- 20:28Speaker 2: iterate over a week set.
- 20:29Speaker 1: Smart for managing metadata on potentially transient objects. Okay, iterating
- 20:34Speaker 1: over these collections in arrays and strings. The iteration protocols.
- 20:38Speaker 1: What's the deal with symbol dot iterator?
- 20:41Speaker 2: Right? For an object to be considered iterable, meaning you
- 20:44Speaker 2: can use it with for out of loops or spread syntax,
- 20:47Speaker 2: it needs to have a method whose key is the
- 20:49Speaker 2: well known symbol symbol dot iterator.
- 20:52Speaker 1: And what does that method do?
- 20:54Speaker 2: That method, when called, must return an iterator object. The
- 20:57Speaker 2: iterator object, in turn, must have an next method.
- 21:00Speaker 1: And next gives you the value.
- 21:02Speaker 2: Calling next returns an object with two properties value the
- 21:06Speaker 2: next value in the sequence and done a boollion that's
- 21:09Speaker 2: false until the iteration is complete, then it becomes true.
- 21:12Speaker 1: So iterable means has symbol dot iterator, which gives an
- 21:15Speaker 1: iterator which has naxt got it.
- 21:18Speaker 2: That's the contract and for.
- 21:19Speaker 1: Data Bouve just handles all that automatically.
- 21:21Speaker 2: Yep fata b loops are designed specifically to work with
- 21:24Speaker 2: this protocol. It calls symbol dot iterator, gets the iterator,
- 21:27Speaker 2: and keeps calling next until done is true, give you
- 21:30Speaker 2: the value at each step. Works on a raise strings, map, sets,
- 21:34Speaker 2: no lists anything.
- 21:35Speaker 1: Iterable much nicer than old four loops with index counters.
- 21:38Speaker 1: Sometimes now generators dot function How do they fit into iteration?
- 21:44Speaker 2: Generators are a special kind of function defined with function.
- 21:47Speaker 2: When you call a generator function, it doesn't run the
- 21:49Speaker 2: code immediately. Instead, it returns a generator object, which is
- 21:53Speaker 2: an iterator.
- 21:54Speaker 1: So calling it gives you the iterator directly.
- 21:57Speaker 2: Yes. Inside the generator function, you use the yield keyword.
- 22:00Speaker 2: Word yield pauses the function's execution and sends a value
- 22:04Speaker 2: out that becomes the value in the value done object.
- 22:07Speaker 3: From next pauses the function Yeah.
- 22:09Speaker 2: The next time you call next on the generator object,
- 22:12Speaker 2: the function resumes exactly where it left off right after
- 22:14Speaker 2: the yield and continues until it hits the next yield
- 22:17Speaker 2: or the end.
- 22:18Speaker 1: Of the function whoa functions that pause and resume.
- 22:21Speaker 2: It's powerful makes writing complex iterators much easier. You can
- 22:25Speaker 2: also use yield to delegate iteration to another iterable or generator.
- 22:29Speaker 1: Fascinating and async iterators a sync function and for a
- 22:33Speaker 1: weight dot f. This is for asynchronous sequences exactly.
- 22:36Speaker 2: ACNC iteration protocols handle sequences where the values arrive asynchronously,
- 22:40Speaker 2: like data streaming over a network, and ACNC literable has
- 22:44Speaker 2: symbol dot ACNC iterator, which returns an ACNC iterator.
- 22:48Speaker 1: And its next method.
- 22:49Speaker 2: Its next method returns a promise that resolves to the
- 22:52Speaker 2: value downe object ah.
- 22:54Speaker 1: So next is async itself.
- 22:56Speaker 2: Right, and the four weight of loop is designed to
- 22:58Speaker 2: work with these. It weighs asynchronously for the promise from
- 23:02Speaker 2: next to resolve before each iteration. Perfect for handling streams
- 23:05Speaker 2: of data like chunks from a fetch response or server
- 23:08Speaker 2: send events.
- 23:10Speaker 3: Very cool.
- 23:10Speaker 1: Okay, let's dive deeper into objects. Property attributes, configurable, innumerable, writable.
- 23:18Speaker 1: What are these internal things?
- 23:19Speaker 2: Every object property has these internal attributes to control its behavior.
- 23:23Speaker 2: Configurable means can the property be deleted or can its
- 23:26Speaker 2: attributes be changed later? Innumerable means does it show up
- 23:29Speaker 2: in four lot loombs, ritable means can its value be changed?
- 23:33Speaker 2: And value holds the actual value.
- 23:34Speaker 1: So they define the meta behavior of the property exactly.
- 23:37Speaker 2: They're also get and set attributes for accessor properties getters
- 23:41Speaker 2: and setters instead of value.
- 23:42Speaker 1: And ritable, and we control these using object dot define property.
- 23:46Speaker 2: Yes, object dot define property lets you define a new
- 23:50Speaker 2: property or modify an existing one and explicitly set these
- 23:54Speaker 2: attribute values like innumerable dot false or ritable dot false.
- 23:58Speaker 2: You can also define getter and setter functions using this
- 24:02Speaker 2: object out defined properties lets you do it for multiple
- 24:04Speaker 2: properties at once.
- 24:05Speaker 1: Gives you fine grain control. Now, object literals have some
- 24:08Speaker 1: nice shorthands these days, right they do.
- 24:10Speaker 2: If you have variable X and you want an object
- 24:12Speaker 2: property x with that variable's value, you can just write
- 24:15Speaker 2: x instead of xx.
- 24:16Speaker 1: Nice. And for methods you can.
- 24:18Speaker 2: Write my methods my method dot function cleaner syntax.
- 24:21Speaker 1: And computed property keys.
- 24:22Speaker 2: Yeah, you can use square brackets inside an object literal
- 24:25Speaker 2: to use the result of an expression as a property
- 24:27Speaker 2: key like prefix plus id. Very dynamic.
- 24:31Speaker 1: These shorthands definitely make object creation less verbose. What about
- 24:35Speaker 1: combining objects object dot A sign. How does it work?
- 24:37Speaker 2: Object out a sign target dot sources copies all innumerable
- 24:41Speaker 2: own properties from the source objects into the target object.
- 24:44Speaker 2: It modifies the target directly and returns.
- 24:46Speaker 1: It copies properties. Is it a deep copy?
- 24:49Speaker 2: No. Crucially, it's a shallow copy. If a property value
- 24:53Speaker 2: is an object or array, only the references copy, not
- 24:56Speaker 2: the nested structure itself. Both the target and source will
- 25:00Speaker 2: point to the same nested object.
- 25:01Speaker 1: Okay, shall I copy important limitation? How does it handle
- 25:05Speaker 1: getter setters?
- 25:06Speaker 2: It invokes getters on the source and copies the resulting
- 25:09Speaker 2: value to the target. It doesn't copy the getter function itself.
- 25:13Speaker 2: Setters aren't copied.
- 25:14Speaker 1: Got it useful for emerging simple objects or applying mix ins?
- 25:18Speaker 1: What about getting values out of objects? Destructuring?
- 25:21Speaker 2: Object destructuring is fantastic. It lets you unpack properties from
- 25:24Speaker 2: an object directly into variables like const name age user.
- 25:28Speaker 1: Much cleaner than constname user dot name constant age user
- 25:31Speaker 1: dot age way cleaner.
- 25:32Speaker 2: You can also rename variables comments, provide default values, constme measures,
- 25:37Speaker 2: and use the rest syntax to collect remaining properties into
- 25:40Speaker 2: a new object. Constant aid rest data.
- 25:43Speaker 1: Super useful for working with API responses or config and
- 25:47Speaker 1: the spread operator also works inside object literals.
- 25:50Speaker 2: Yes, similar to object dot assign it lets you spread
- 25:53Speaker 2: the properties of an existing object into a new object
- 25:56Speaker 2: literal constant new user u uzer age thirty one is
- 26:02Speaker 2: admin false. Also a shallow copy. Great for creating modified
- 26:07Speaker 2: copies of objects nondestructively.
- 26:09Speaker 1: Okay, spread for creating new objects based on old ones.
- 26:12Speaker 1: Now the tricky this keyword. Its value depends on how
- 26:16Speaker 1: a function.
- 26:16Speaker 2: Is called right, hugely depends on the call site. In
- 26:19Speaker 2: a regular function called directly, not as an object method,
- 26:23Speaker 2: this is the global object window and browsers in non
- 26:26Speaker 2: strict mode and undefined as strict mode.
- 26:28Speaker 1: Okay, what about when it's a method like an object
- 26:31Speaker 1: dot do something.
- 26:31Speaker 2: Then this inside do something refers to object the object
- 26:34Speaker 2: the method was called on.
- 26:35Speaker 1: Makes sense, and we can explicitly set this yep.
- 26:37Speaker 2: Using function dot call this rg R one, function dot
- 26:40Speaker 2: apply this ars array, or function dot bind this arg
- 26:43Speaker 2: which returns a new function permanently bound to that this value.
- 26:46Speaker 1: And ero functions they're different.
- 26:48Speaker 2: Completely different regarding this erofunctions don't have their own this.
- 26:52Speaker 2: They lexically capture this value from their surrounding scope at
- 26:56Speaker 2: the time they are defined. This solves many old problems,
- 26:59Speaker 2: especially with callbacks inside methods that lexical.
- 27:02Speaker 1: This in aerow functions is a key feature. Okay, let's
- 27:05Speaker 1: talk inheritance prototypes. This is JavaScript's core inheritance model, right,
- 27:11Speaker 1: not classes, initially.
- 27:12Speaker 2: Correct, JavaScript uses prototype based inheritance. Every function is a
- 27:16Speaker 2: prototype property, which is an object. When you use a
- 27:19Speaker 2: function as a constructor with new the object created inherence
- 27:23Speaker 2: from the constructor's prototype, object inherits.
- 27:26Speaker 1: How does that work?
- 27:26Speaker 2: Every object has an internal link, often accessible via proto,
- 27:30Speaker 2: though object dot get prototype of is the standard way
- 27:33Speaker 2: to read it to its prototype. When you try to
- 27:36Speaker 2: access a property on an object, if the object doesn't
- 27:38Speaker 2: have it directly, JavaScript looks at its prototype. If the
- 27:41Speaker 2: prototype doesn't have it, it looks at its prototype, and so
- 27:44Speaker 2: on up the chain.
- 27:45Speaker 1: The prototype chain, so properties are looked up along this
- 27:47Speaker 1: chain exactly.
- 27:49Speaker 2: That's how inheritance works. Methods defined on a constructor's prototype
- 27:53Speaker 2: are shared by all instances created from that constructor. You
- 27:56Speaker 2: can use object dot is prototype of another object to
- 28:00Speaker 2: check the chain relationship.
- 28:01Speaker 1: Okay, Prototypes are the real mechanism. So what about ES
- 28:04Speaker 1: six class syntax? Is that just sugar on top.
- 28:08Speaker 2: Pretty much class provides a cleaner, more familiar syntax for
- 28:11Speaker 2: setting up constructor functions and their prototypes. The constructor method
- 28:15Speaker 2: inside a class defines the constructor function. Other methods defined
- 28:19Speaker 2: in the class body automatically get added to the class's prototype.
- 28:23Speaker 1: So it makes prototype inheritance look more like classical inheritance.
- 28:27Speaker 2: Kind of yes, it simplifies the syntax. Class also introduces
- 28:31Speaker 2: features like static members belonging to the class itself, not instances,
- 28:35Speaker 2: and more recently, private members using the hashtag prefix for
- 28:39Speaker 2: true encapsulation. But underneath it's still leveraging the prototype chain.
- 28:43Speaker 1: Good to know classes mostly syntax over the existing prototype system. Okay,
- 28:47Speaker 1: let's focus specifically on functions. Now different ways to define
- 28:50Speaker 1: them declarations, expressions, arrows right.
- 28:53Speaker 2: Function declarations look like function my function. These are fully hoisted.
- 28:57Speaker 2: You can call them before they appear in the.
- 28:59Speaker 1: Code hoisted okay, and expressions.
- 29:01Speaker 2: Function expressions assign a function to a variable like co
- 29:04Speaker 2: hocal function or constant my aerowfunk. With these, only the
- 29:07Speaker 2: variable declaration constant my funk is hoisted, not the function
- 29:11Speaker 2: assignment itself. You can't call them before the line where
- 29:14Speaker 2: they're assigned.
- 29:14Speaker 1: So declarations are fully hoisted expressions including arrows are not correct.
- 29:19Speaker 2: And aero functions have that concise syntax in the lexical
- 29:22Speaker 2: this binding we talked about. There's also the function constructor
- 29:26Speaker 2: new function ab return of plus b, but it's generally discouraged.
- 29:29Speaker 2: Like evil, it executes code from strings, which is slow
- 29:33Speaker 2: and potentially insecure.
- 29:34Speaker 1: Stick to declarations, expressions and arrows. Then, what about handling
- 29:39Speaker 1: arguments rest parameters.
- 29:41Speaker 2: Rest parameters dot orgs let you gather an indefinite number
- 29:46Speaker 2: of trailing arguments passed to a function into a single
- 29:49Speaker 2: real array named arcs, much better than the old arguments.
- 29:53Speaker 1: Object and spread syntax in function calls.
- 29:56Speaker 2: That does the opposite. It takes an iterable like an
- 29:59Speaker 2: array and expands it into individual arguments. When calling a
- 30:03Speaker 2: function my function dot my array.
- 30:07Speaker 1: So rest collects arguments into an array. Spread expands an
- 30:10Speaker 1: array into arguments. Got it and default parameter values.
- 30:13Speaker 2: Yeah, you can set defaults directly in the signature function creed.
- 30:17Speaker 2: If the argument isn't provided or is undefined, the default
- 30:20Speaker 2: is used. Makes functions more robust.
- 30:22Speaker 1: We covered hoisting already. How about functions as values first
- 30:25Speaker 1: class functions?
- 30:26Speaker 2: It just means functions in JavaScript are treated like any
- 30:28Speaker 2: other value. You can assign them to variables, store them
- 30:31Speaker 2: in arrays or objects, pass them as arguments to other
- 30:34Speaker 2: functions callbacks, and return them from functions higher order functions.
- 30:39Speaker 2: This is fundamental to functional programming patterns in JS.
- 30:42Speaker 1: Very flexible. What about the caller property and the arguments
- 30:45Speaker 1: object still relevant?
- 30:47Speaker 2: The argument's object exists in non arrow functions. It's an
- 30:51Speaker 2: array like object holding all past arguments. But rest parameters
- 30:54Speaker 2: are generally preferred now because they give you a real array.
- 30:58Speaker 2: Arguments dot collie refers to the current function and arguments
- 31:01Speaker 2: dot caller or function dot caller refers to the calling
- 31:04Speaker 2: function are deprecated, non standard and forbidden in strict mode.
- 31:09Speaker 2: Avoid them good to know.
- 31:10Speaker 1: Stick with rest parameters. Finally, execution context, scope chain, and closure.
- 31:15Speaker 2: These sound deep, they are core concepts and execution context
- 31:19Speaker 2: is like the environment where code runs includes the variables
- 31:23Speaker 2: scope this value. When a function is called, a new
- 31:25Speaker 2: context is created. The scope chain, as we said, is
- 31:29Speaker 2: how JS looks up variables by checking the current scope,
- 31:32Speaker 2: then outer scopes.
- 31:33Speaker 1: Enclosure.
- 31:34Speaker 2: Closure is when a function remembers its lexical scope the
- 31:37Speaker 2: variables from the environment where it was created, even when
- 31:39Speaker 2: the function is executed outside that original scope, so an.
- 31:42Speaker 1: Inner function can still access the outer function's variables. After
- 31:46Speaker 1: the outer function has finished running.
- 31:48Speaker 2: Exactly, the inner function closes over the outer scope's variables.
- 31:52Speaker 2: This enables powerful patterns like data privacy, creating private like
- 31:56Speaker 2: variables and functions that maintain state between calls.
- 31:59Speaker 1: Closures are powerful. Okay, asynchronous JavaScript promises a better way
- 32:04Speaker 1: than callbacks.
- 32:05Speaker 2: Oh, definitely. Promises represent the eventual result of an ACINC operation.
- 32:10Speaker 2: A promise object is a placeholder for a future value.
- 32:13Speaker 2: It starts an appending state, and then it eventually settles
- 32:16Speaker 2: into either a fulfilled state if the operation succeeded with
- 32:20Speaker 2: the result value, or a rejected state if it failed
- 32:22Speaker 2: with an error or reason.
- 32:24Speaker 1: How do we create them?
- 32:25Speaker 2: Usually using new promise resolve reject inside that function the executor,
- 32:29Speaker 2: you perform your ACNC operation. When it's done, you call
- 32:32Speaker 2: resolve value on success or reject error on failure.
- 32:35Speaker 1: And how do we use the result or handle the error?
- 32:38Speaker 3: Then and dot catch Precisely.
- 32:39Speaker 2: You chain that on fulfilled unrejected onto a promise. Unfulfilled
- 32:43Speaker 2: runs if it resolves getting the value, on rejected runs
- 32:46Speaker 2: if it rejects getting the error catch unrejected is just
- 32:50Speaker 2: shorthand for that null unrejected, focusing.
- 32:53Speaker 1: Only on errors, and then returns another promise. That's how
- 32:56Speaker 1: chaining works.
- 32:56Speaker 2: Yes, each then or dot catch returns a new promise,
- 33:00Speaker 2: allowing you to chain asynchronous steps together in a much
- 33:03Speaker 2: cleaner way than nested callbacks callback hell. The handlers in
- 33:07Speaker 2: then are also non reentrant. They won't be called immediately
- 33:10Speaker 2: if the promise is already settled, they get cued.
- 33:13Speaker 1: Very elegant. What about managing multiple promises? Promise dot all
- 33:17Speaker 1: promise dot race.
- 33:19Speaker 2: Yeah, useful static methods. Promise dot all promises waits for
- 33:23Speaker 2: all promises in the input iterable to fulfill. If any
- 33:26Speaker 2: reject it rejects immediately, it resolves with an array of
- 33:29Speaker 2: the results.
- 33:30Speaker 1: Okay, waits for all successes.
- 33:32Speaker 2: Promise dot all settled promises waits for all promises to settle,
- 33:36Speaker 2: either fulfill or reject it always fulfills, returning an array
- 33:40Speaker 2: of objects describing the outcome of each promise.
- 33:42Speaker 1: Safer if you need to know about all outcomes, even failures.
- 33:45Speaker 2: Right. Promise dot race promises settles as soon as the
- 33:49Speaker 2: first promise in the terable settles either fulfills or rejects,
- 33:52Speaker 2: It takes on the outcome of that first one, a
- 33:54Speaker 2: race to the finish and promise. Any promises resolves as
- 33:58Speaker 2: soon as the first promise fulfills. It only rejects if
- 34:01Speaker 2: all promises reject and it rejects with a special aggregate error.
- 34:04Speaker 1: Useful if you just need one success out of many possibilities.
- 34:08Speaker 1: What about serial promise composition executing promises one after another.
- 34:13Speaker 2: That's often just standard dend chaining. You ensure one acinc
- 34:16Speaker 2: operation completes before starting the next, often passing the result
- 34:19Speaker 2: along a synca weight makes this look even more sequential.
- 34:23Speaker 1: Speaking of timing the micro test queue, how does that
- 34:26Speaker 1: affect promises?
- 34:27Speaker 2: Promise dot then and dot catch callbacks don't run immediately
- 34:31Speaker 2: when a promise settles, its handlers are scheduled to run
- 34:34Speaker 2: in the micro task queue. This queue has higher priority
- 34:37Speaker 2: than the main macro task queue, which handles things like
- 34:40Speaker 2: set time out or user events.
- 34:42Speaker 1: So promise callbacks run very soon after the current synchronous
- 34:45Speaker 1: code finishes, but before the next timer.
- 34:47Speaker 2: Or event exactly. It ensures a predictable execution order for
- 34:51Speaker 2: promise reactions happening after the current task but before the
- 34:54Speaker 2: browser does other things like rendering got it?
- 34:57Speaker 1: And why is it crucial to avoid unhandled rejection?
- 35:00Speaker 2: If a promise rejects and nothing catches that rejection you
- 35:04Speaker 2: dot catch or unrejected handler in a dot catch, then
- 35:08Speaker 2: it's an unhandled rejection. Modern environments will log errors to
- 35:13Speaker 2: the console, and in some cases, like no JS, it
- 35:16Speaker 2: might even terminate the process. You always want to handle
- 35:19Speaker 2: potential errors to keep your application stable.
- 35:21Speaker 1: I always have a dot catch somewhere down the chain.
- 35:24Speaker 1: What about promise extensions like cancelation or progress? Are those standard?
- 35:28Speaker 2: No, they aren't part of the official trauma specification. Cancelation
- 35:32Speaker 2: the ability to stop an ongoing async operation tied to
- 35:36Speaker 2: a promise, and progress notifications getting updates before it finishes
- 35:41Speaker 2: are things you usually implement with libraries or custom patterns,
- 35:44Speaker 2: often using mechanisms like the abort controller, which we'll touch
- 35:47Speaker 2: on with fetch.
- 35:47Speaker 1: Okay, so not built in now? Asinc and a weight
- 35:50Speaker 1: this is syntactic sugar on top of promises right makes
- 35:53Speaker 1: ACYNC code look synchronous exactly.
- 35:55Speaker 2: You mark a function with the acinc keyword inside that function,
- 35:59Speaker 2: you can use the awake word before a promise.
- 36:01Speaker 1: And what does a weight do?
- 36:02Speaker 2: It? Pauses the execution of the acing function at that
- 36:05Speaker 2: point until the promise you're awaiting settles.
- 36:08Speaker 1: Pauses the function, not the whole browser, just.
- 36:10Speaker 2: The acing function. It asynchronously waits if the promise fulfills
- 36:14Speaker 2: a weight, returns is the result value. If the promise
- 36:17Speaker 2: rejects a weight, throws that rejection reason as an error.
- 36:21Speaker 1: So you can use try dot catch around awake.
- 36:24Speaker 2: Yes, that's the beauty. You can use standard try dot
- 36:27Speaker 2: catch dot finally blocks for error handling. Just like synchronous code,
- 36:31Speaker 2: an ACYNC function itself implicitly returns a promise that resolves
- 36:34Speaker 2: with the function's return value or rejects if an uncaught
- 36:37Speaker 2: error occurs inside it.
- 36:39Speaker 1: That sounds much easier to read and write than loss
- 36:41Speaker 1: of dot chains. Where can we use.
- 36:42Speaker 2: A weight only directly inside an acing function? You can't
- 36:45Speaker 2: just sprinkle a weight anywhere In regular synchronous code. You
- 36:48Speaker 2: might use an immediately invoked acing function expression iiaff e
- 36:53Speaker 2: like acink a weight to use a weight at the
- 36:55Speaker 2: top level of a module if needed.
- 36:57Speaker 1: Gotcha. So for serial execution, instead of then, we just await, await, await.
- 37:02Speaker 2: Pretty much concer result one will await step one const
- 37:05Speaker 2: result two. Await step two Result one looks very linear
- 37:08Speaker 2: and clear.
- 37:08Speaker 1: Fantastic. What about running things in parallel with they sink away,
- 37:12Speaker 1: but handling errors safely rejection safe parallelization.
- 37:16Speaker 2: Right if you just await promise dot all P one,
- 37:19Speaker 2: P two, p three, the whole thing rejects if any
- 37:22Speaker 2: of them reject. If you want to get results even
- 37:25Speaker 2: if some fail, you could await promise dot all settled,
- 37:28Speaker 2: which always results and tells you the status of each.
- 37:31Speaker 2: Or you could map your promises and handle errors individually,
- 37:34Speaker 2: perhaps using a weight p dot catch EP do or
- 37:38Speaker 2: within the mapping or wrapping awights in individual try dot
- 37:41Speaker 2: catch blocks if doing them sequentially.
- 37:43Speaker 1: So options exist to manage parallel tasks gracefully even with failures. Great.
- 37:47Speaker 1: Let's shift to the browser environment itself, the browser object
- 37:50Speaker 1: model BOM. What does this cover?
- 37:52Speaker 2: The BOMB represents the browser window and its features, distinct
- 37:55Speaker 2: from the HTML document content, which is the DOM. The
- 37:59Speaker 2: core object is which is the global object.
- 38:01Speaker 1: In browsers, and we can find out where the user.
- 38:03Speaker 2: Has scrolled YEP, window dot scroll x or paychecks offset
- 38:07Speaker 2: and window dust scrolly or pageops. I could give you
- 38:09Speaker 2: the horizontal and vertical scroll positions in pixels.
- 38:11Speaker 1: What about opening new windows? Window dot open pop up
- 38:14Speaker 1: blockers are a thing.
- 38:15Speaker 2: Though they are Window dot open ural name features tries
- 38:20Speaker 2: to open a new window or tab, but browsers usually
- 38:22Speaker 2: block this unless it happens right after a direct user
- 38:25Speaker 2: action like a click. You must check the return value
- 38:28Speaker 2: of window dot open. If it's null, the pop up
- 38:31Speaker 2: was likely blocked.
- 38:32Speaker 1: Good check. Timers set time out and set interval. How
- 38:35Speaker 1: do they work with the single thread.
- 38:37Speaker 2: Set time out callback delay runs the callback once after
- 38:40Speaker 2: at least delay milliseconds. Set interval runs the callback repeatedly
- 38:44Speaker 2: every interval milliseconds. Because JavaScript is single threaded and uses
- 38:48Speaker 2: an event loop, the delay is a minimum. The callback
- 38:51Speaker 2: actually runs only when the main thread is free after
- 38:53Speaker 2: the delay is passed. Set time out returns an ID
- 38:56Speaker 2: you can pass to clear timeout to cancel it. Set
- 38:59Speaker 2: interval returns an id for clear.
- 39:00Speaker 1: Interval minimum delay not exact. Dot IT navigation, location and
- 39:04Speaker 1: history oobjects.
- 39:05Speaker 2: Location gives info about the current url location dot href, location,
- 39:09Speaker 2: dot path name, location, dot searchlocation, dot hash, et cetera,
- 39:12Speaker 2: and lets you navigate by assigning to location dot h
- 39:15Speaker 2: ref or using methods like location dot sign. You all
- 39:18Speaker 2: navigates and ads to history location dot replace, heural navigates
- 39:22Speaker 2: but replaces current history entry and location dot reload and
- 39:25Speaker 2: history history lets you move through the user session history
- 39:28Speaker 2: dot backstory, dot forward history dot go in where N
- 39:31Speaker 2: can be positive or negative. History dot link tells you
- 39:34Speaker 2: how many items are in.
- 39:35Speaker 1: The history stack, useful for custom back forward buttons. What
- 39:38Speaker 1: about the navigator object? What browserinfo does it?
- 39:41Speaker 2: Whole navigator gives you browsersniffinginfo, though user agent is notoriously unreliable.
- 39:45Speaker 2: Better info comes from properties like Navigator dot Language, Navigator
- 39:49Speaker 2: dot platform. Crucially, it has Navigator dot online booley in
- 39:53Speaker 2: for connection status and events online offline. The Navigator Dot
- 39:56Speaker 2: Connection object Network Information API provides more tas like connection type,
- 40:01Speaker 2: effective type, speed, downlink rtt OTT and a change event.
- 40:05Speaker 1: Network INFOS sounds handy, and the screen object.
- 40:08Speaker 2: Screen tells you about the users display screen dot width,
- 40:10Speaker 2: screen dot height, screen dot availwith excluding os interfaces, screen
- 40:14Speaker 2: dot color depth, screen dotpixel depth, screen dot orientation.
- 40:18Speaker 1: Good for responsive design decisions. Can we control audio and
- 40:21Speaker 1: video via.
- 40:22Speaker 2: The bo yes HTML media elements Audio video have a
- 40:25Speaker 2: rich JavaScript API. You can play, pause, control volume, get duration,
- 40:30Speaker 2: get and set current time. They fire lots of events
- 40:33Speaker 2: play pause and a time update, canplay error, etc. You
- 40:37Speaker 2: can use canplay type mime type to check codec support.
- 40:40Speaker 1: Full media control. The URL object better than string manipulation
- 40:45Speaker 1: much better.
- 40:45Speaker 2: New url string parses a URL string into an object
- 40:48Speaker 2: with properties for easy access to protocol, host name, path, names, search, hash,
- 40:52Speaker 2: et cetera. It also has search perms and objects specifically
- 40:54Speaker 2: for manipulating query string parameters easily.
- 40:57Speaker 1: Nice and performance monitoring dot performance dot.
- 40:59Speaker 2: Now Yeah, the performance API is key for measuring speed.
- 41:03Speaker 2: Performance dot now gives high resolution timestamps. You can create
- 41:07Speaker 2: name markers with performance dot mark start task, measure durations
- 41:11Speaker 2: between marks with performance dot measure task duration, start task
- 41:14Speaker 2: and task and retrieve these entries with performance dot get entries.
- 41:19Speaker 2: The Navigation Timing API Performance Navigation Timing gives detailed timings
- 41:23Speaker 2: for pageload.
- 41:24Speaker 1: Stages, essential for optimization. Okay, let's switch to the Document
- 41:27Speaker 1: Object Model DOM. This is about the page content itself,
- 41:31Speaker 1: the HTML structure exactly.
- 41:33Speaker 2: The DOM represents the HTML document as a tree of nodes, elements, text, comments, attributes.
- 41:39Speaker 2: The document object is.
- 41:40Speaker 1: The root, and nodes have properties and relationships.
- 41:43Speaker 2: Yep. Node type tells you what it is, element, texts
- 41:45Speaker 2: et cetera. Note name gives the tag name for elements.
- 41:48Speaker 2: Node value gives the content for text nodes. Relationships like
- 41:51Speaker 2: parent node child nodes first child, last child, next sibling,
- 41:54Speaker 2: previous sibling. Let you navigate this tree structure.
- 41:57Speaker 1: How do we grab specific elements? To start with? Element
- 42:00Speaker 1: by id.
- 42:01Speaker 2: That's a classic for unique ideas. Get elements by tag
- 42:04Speaker 2: name gets a live HTML collection of elements by tag.
- 42:07Speaker 2: Get elements by name gets a live nodalist by the
- 42:09Speaker 2: name attribute. There's also document dot, document element, the h
- 42:13Speaker 2: nolande and document dot body.
- 42:15Speaker 1: Right different ways to get elements. How do we change
- 42:18Speaker 1: things add or remove nodes.
- 42:19Speaker 2: You can document dot create element tag name and document
- 42:22Speaker 2: dot create text node, then use parentode dot a pen
- 42:26Speaker 2: child new node to add it at the end, or
- 42:28Speaker 2: parentnode dot insert before new node, reference node to insert
- 42:31Speaker 2: before another node. Use parentnode dot remove child node to
- 42:35Speaker 2: remove and parentode dot replace child new node old node
- 42:37Speaker 2: to replace document dot create. Document fragment is useful for
- 42:41Speaker 2: building a chunk of dom off screen before appending it
- 42:44Speaker 2: all at once for better performance.
- 42:45Speaker 1: Document fragments for batch updates. Good tip what about using
- 42:48Speaker 1: CSS selectors dot query selector yes.
- 42:51Speaker 2: Query selector selector returns the first matching element, and query
- 42:55Speaker 2: selectora selector returns a static nodalist of all matching elements.
- 42:58Speaker 2: These are incredibly powerful on it available on document fragments
- 43:01Speaker 2: and individual elements, much more flexible than the older get
- 43:04Speaker 2: elements by methods and.
- 43:06Speaker 1: Get elements by class name was added later.
- 43:08Speaker 2: Right get elements by class named it gets a live
- 43:10Speaker 2: HTML collection based on class names, also useful.
- 43:13Speaker 1: Okay, we have the element, how do we change its content?
- 43:16Speaker 1: Inner HTML, text content, etc.
- 43:18Speaker 2: Inner HTML gets or sets the HTML content inside an element.
- 43:22Speaker 2: Setting it parses the string as HTML. Outer HTML includes
- 43:27Speaker 2: the element itself. Text content gets or sets only the
- 43:30Speaker 2: text content, ignoring HTML tags and encoding entities when setting.
- 43:35Speaker 2: Intertext is similar to text content, but is aware of
- 43:37Speaker 2: CSS rendering. It omits hidden text and also codes entities differently.
- 43:43Speaker 2: Be careful with inner HTML as it can be slow
- 43:45Speaker 2: and requires reattaching event listeners to recreated elements.
- 43:48Speaker 1: Good point about listeners. How do we change styles? Dot element, dot.
- 43:51Speaker 2: Style, element dot style accesses the elements inline style attribute.
- 43:55Speaker 2: You set properties like element dot style, dot background color
- 43:57Speaker 2: red to get the actual computed style including styles from
- 44:00Speaker 2: CSS rules. Use window dot get computed style element. You
- 44:04Speaker 2: can also access style sheets via document dot style sheets
- 44:06Speaker 2: and manipulate CSS rules, CSS rule CSS style directly, though
- 44:10Speaker 2: that's less common.
- 44:11Speaker 1: Inline versus computed style makes sense. What about element size
- 44:15Speaker 1: and position offset client scroll.
- 44:17Speaker 2: Dimensions to give different measurements offset offset offset with offset
- 44:21Speaker 2: left offset top includes borders and padding and position relative
- 44:25Speaker 2: to the offset parent client client height client with is
- 44:29Speaker 2: the inner size, padding included, border, scroll bars excluded, scroll
- 44:34Speaker 2: height scroll width is the total size of the scrollable content,
- 44:38Speaker 2: while scroll left scroll top is the current scroll position
- 44:41Speaker 2: within the element. Client dimensions are read.
- 44:44Speaker 1: Only different numbers for different use cases. What if we
- 44:47Speaker 1: need more advanced dom traversal no iterator and tree walker.
- 44:50Speaker 2: These are for more complex iteration needs. They let you
- 44:53Speaker 2: traverse a subtree of the dome, optionally filtering nodes based
- 44:56Speaker 2: on criteria you define, especially tree walker, which has a
- 44:59Speaker 2: filter function. They give you finer control than simple loops
- 45:02Speaker 2: or recursive functions. Sometimes true walker keeps track of the
- 45:05Speaker 2: current node.
- 45:06Speaker 1: Specialized tools and DOM ranges selecting parts of the document.
- 45:10Speaker 2: Yeah. Document dot creator range creates a range object representing
- 45:14Speaker 2: a contiguous section of the document, you can set its
- 45:17Speaker 2: start and end points. Set start, set end. Then you
- 45:21Speaker 2: can manipulate that selected content. Delete contents, extract contents into
- 45:25Speaker 2: a document fragment, clone contents, and certain nodes around contents.
- 45:29Speaker 2: Useful for things like text editors or highlighting.
- 45:31Speaker 1: Powerful selection manipulation. Lastly, for DOM intersection observer and resize
- 45:36Speaker 1: observer modern ways to react to visibility and size changes.
- 45:40Speaker 2: Exactly intersection observer new intersection Observer callback efficiently tells you
- 45:45Speaker 2: when an element intersects with the viewport or another development.
- 45:49Speaker 2: Great for lazy loading images, infinite scroll triggering animations on
- 45:52Speaker 2: view resize observer new resize observer callback efficiently tells you
- 45:56Speaker 2: when an element size changes, much better than pulling off
- 45:59Speaker 2: stwidth constantly. Both are asynchronous in performance focus.
- 46:02Speaker 1: Do you sound like essential modern tools? Okay? Events making
- 46:05Speaker 1: pages interactive? DON level zero Level two.
- 46:08Speaker 2: DOM level zero is the old way. Element dot on
- 46:10Speaker 2: click will function simple, but only one handler per event
- 46:14Speaker 2: type and only runs in the bubbling phase. This inside
- 46:17Speaker 2: is the element removed by setting to NOL and.
- 46:19Speaker 1: Level two the modern way.
- 46:21Speaker 2: DOM level two introduced element dot ad event listener type listener,
- 46:25Speaker 2: use capture This is the standard. You can add multiple listeners.
- 46:28Speaker 2: The third argument use capture boolli in or options object
- 46:32Speaker 2: lets you choose whether to listen during the capturing phase
- 46:34Speaker 2: down the tree or the bubbling phase up the tree.
- 46:37Speaker 2: The default you remove listeners with remove event listener, needing
- 46:40Speaker 2: the exact same arguments.
- 46:41Speaker 1: AD event listener is the way to go. When an
- 46:43Speaker 1: event happens, we get an event object. What's in it?
- 46:46Speaker 2: Lots of useful stuff? Event dot type like click, event
- 46:49Speaker 2: dot target, the element the event originated on, event dot
- 46:52Speaker 2: current target the element the listener is attached to. Event
- 46:55Speaker 2: dot prevent default, stop to full browseractions, event dot stop
- 46:58Speaker 2: propagation to stop bubbling cap Also details like coordinates, client x, clinyy, modifier, keys, feature,
- 47:05Speaker 2: l key, old key, event phase, et cetera. Properties vary
- 47:08Speaker 2: a bit by event type.
- 47:09Speaker 1: Lots of context. What are some common event types we handle?
- 47:12Speaker 2: Oh tons load for window, images of scripts, unload, window focused,
- 47:16Speaker 2: blur or form fields, window, mouse, events, click, TVL click, mousedown,
- 47:19Speaker 2: mouse oup, mouse over, mouse out, mouse enter, mouse leave wheel,
- 47:22Speaker 2: keyboard events, key down, keep us key at form events, submit,
- 47:25Speaker 2: change input, clipboard events, touch events, many more.
- 47:30Speaker 1: A whole universe of events. Can we trigger events ourselves
- 47:33Speaker 1: in code simulate them?
- 47:35Speaker 2: Yes, it's a bit verbose. Use document dot create event
- 47:38Speaker 2: like mouse events, then initialize it with details using a
- 47:41Speaker 2: method like event dot inn at mouse event or newer
- 47:44Speaker 2: constructors like new mouse event or new custom event. Finally,
- 47:47Speaker 2: dispatch it on an element using element dot dispatch.
- 47:50Speaker 1: Event create initialized dispatch guid. For smooth animations, request animation frame.
- 47:54Speaker 3: How did that work?
- 47:55Speaker 2: Instead of timers like set timeout, use request animation frame callback.
- 47:59Speaker 2: The brow sol so calls your callback function just before
- 48:02Speaker 2: it's about to repaint the screen. The sinks your animation
- 48:04Speaker 2: logic perfectly with the browser's rendering cycle, making animations much
- 48:08Speaker 2: smoother and more efficient. It passes a high resolution timestamp
- 48:11Speaker 2: to the callback. You call it recursively within the callback
- 48:14Speaker 2: to continue the animation loop. Use cancel animation frame to
- 48:17Speaker 2: stop it.
- 48:17Speaker 1: Perfect for performance animations.
- 48:19Speaker 3: Okay.
- 48:20Speaker 1: HTML five APIs canvas for drawing.
- 48:22Speaker 2: Yes, the canvas element gives you a drawing surface. You
- 48:25Speaker 2: get the two D context with canvas dot get context
- 48:27Speaker 2: two D. This context object has tons of methods for
- 48:30Speaker 2: drawing shapes, rectangles, lines, arcs, curves with begin path moved
- 48:34Speaker 2: to a line to arc et cetera. Filling, fil style, fill, stroking,
- 48:37Speaker 2: stroke style, stroke struck, drawing text on fill text, applying transformations, translate, rotate, scale,
- 48:42Speaker 2: drawing images, dramage, adding shadows, gradients, patterns, clipping, compositing, global
- 48:46Speaker 2: composite operation and even pixel manipulation. Get image data, put
- 48:50Speaker 2: image data wow.
- 48:51Speaker 1: Full two D graphics engine and WebGL for three D
- 48:53Speaker 1: also on canvas.
- 48:54Speaker 2: YEP, canvas, dot get context, WEBNIL or webjail two. It's
- 48:58Speaker 2: based on OPENNGLS, providing low level access to the GPU
- 49:02Speaker 2: for hardware accelerated two D and three D graphics. You
- 49:05Speaker 2: define geometry in buffers, write vertex and fragment shaders in GLSL,
- 49:09Speaker 2: link them into programs, past data via attributes and uniforms,
- 49:13Speaker 2: and then issue draw calls, drawrays, draw elements. Much more
- 49:17Speaker 2: complex than two D canvas, but incredibly powerful.
- 49:19Speaker 1: High performance three D on the web. Forms got upgrades
- 49:22Speaker 1: in HTML five to two, new types, validation, big.
- 49:25Speaker 2: Time, new input types like email, earle date number with
- 49:28Speaker 2: built in UI and validation attributes like required pattern min max,
- 49:32Speaker 2: the constraint validation API element dot validity, element dot check, validity,
- 49:37Speaker 2: element dot set custom validity, the invalid event programmatic submission
- 49:40Speaker 2: with form dot submit. Fans like input change, clipboard events, copycut, paste,
- 49:44Speaker 2: ridge text editing via the content editor attribute and document
- 49:47Speaker 2: dot exec command, though the latter is getting replaced by
- 49:50Speaker 2: newer APIs. So like boxes also have a good API
- 49:52Speaker 2: from manipulating options.
- 49:53Speaker 1: Forms are much smarter now, Okay, shifting to general JavaScript
- 49:57Speaker 1: APIs atomics and shared airy buffer for worker community.
- 50:00Speaker 2: Yes. This enables shared memory between multiple web workers and
- 50:03Speaker 2: the main thread shared The rebuffer is a buffer whose
- 50:06Speaker 2: underlying memory can be accessed by multiple threads simultaneously. Atomics
- 50:10Speaker 2: provide special functions atomics, dot ad atomics, dot load atomics,
- 50:14Speaker 2: dot store atomics, dot weight atomics, dot notify, et cetera
- 50:17Speaker 2: that perform operations on that shared memory in an atomic way,
- 50:21Speaker 2: preventing race conditions and ensuring operations aren't interrupted. Very advanced,
- 50:25Speaker 2: high performance stuff for parallel computation.
- 50:27Speaker 1: Shared memory powerful, but needs care. Clipboard API a better
- 50:32Speaker 1: way to copy paste.
- 50:33Speaker 2: Navigator dot Clipboard provides an async promise based API right
- 50:37Speaker 2: text read text write for more complex data like images
- 50:41Speaker 2: using clipboard item objects read. It's generally more secure as
- 50:44Speaker 2: it often requires user permission, especially for reading. Also integrates
- 50:48Speaker 2: with the copycut.
- 50:48Speaker 1: Paste events, asynchronous and permission based sounds. Safer cross context
- 50:52Speaker 1: messaging post message.
- 50:54Speaker 2: Window dot post message message target origin allows safe communication
- 50:58Speaker 2: between different windows I frame are workers, even if they're
- 51:01Speaker 2: from different origins. The sender specifies the target origin for security,
- 51:06Speaker 2: The receiver listens for the message, event checks event dot
- 51:09Speaker 2: origin to verify the sender, and accesses the data via
- 51:12Speaker 2: event dot data crucial for secure cross domain communication and
- 51:16Speaker 2: things like embedded widgets.
- 51:17Speaker 1: It's your window to Window Talk encoding API. Text encoder,
- 51:21Speaker 1: text decoder.
- 51:23Speaker 2: Simple but essential. Textingcoder converts a JavaScript string into a
- 51:26Speaker 2: U and data array of UTFA bytes by default. Text
- 51:30Speaker 2: cooder decoder, dot decode uit data array converts an array
- 51:33Speaker 2: of bytes back into a JavaScript string. Handling different encodings
- 51:36Speaker 2: useful when dealing with binary data from files or network
- 51:38Speaker 2: requests that represents.
- 51:39Speaker 1: Text, handling texting codings properly. Blob and file APIs for
- 51:44Speaker 1: raw data and filed.
- 51:45Speaker 2: Blob represents immutable raw data like a junk of binary data.
- 51:48Speaker 2: File inherits from blob and adds file specific metadata like name, size, type,
- 51:53Speaker 2: last modified usually comes from an input type file or
- 51:55Speaker 2: drag and drop file reader reads the contents of blobs
- 51:58Speaker 2: files asynchronously to text read as air buffer read as
- 52:01Speaker 2: dator RRL. With events like onload on air. You can
- 52:05Speaker 2: create object URLs url dot create creature l blob for
- 52:10Speaker 2: referencing blobs files directly in things like MMG tags, but
- 52:13Speaker 2: remember to URL revoke objet url when done.
- 52:16Speaker 1: Comprehensive file handling. Full screen API making things take over
- 52:19Speaker 1: the screen.
- 52:20Speaker 2: Element dot request full screen ask the browser to make
- 52:23Speaker 2: an element full screen requires user gesture usually document dot
- 52:26Speaker 2: a inst full screen to leave document dot full screen.
- 52:29Speaker 2: Element tells you what's full screen full screen change event
- 52:31Speaker 2: fires when state changes. Good for videos, games, presentations.
- 52:35Speaker 1: Immersive experiences. Geolocation API finding the user's.
- 52:39Speaker 2: Location navigator dot geolocation methods get current positions success ab
- 52:44Speaker 2: air CB options and watch position success CB air CB
- 52:48Speaker 2: options needs user permission. Success callback gets a position object
- 52:52Speaker 2: with chords latitude, longitude accuracy. Error callback gets position aer
- 52:56Speaker 2: codes for permission denied, unavailable, timeout, use eaht TPS. Be
- 53:01Speaker 2: mindful of privacy.
- 53:02Speaker 1: Permission and privacy first. Other device APIs orientation network info.
- 53:06Speaker 2: Yeah, we mentioned navigator dot connection for network details. Device
- 53:09Speaker 2: orientation events. Device orientation, give alpha beta gamma values for
- 53:14Speaker 2: physical orientation if hardware supported. Others like battery API are
- 53:18Speaker 2: mostly deprecated. Provides context about the device environment.
- 53:21Speaker 1: Good context fetch API the modern way for network.
- 53:23Speaker 2: Requests absolutely fetch EARL options is the standard. Returns a
- 53:27Speaker 2: promise that resolves to a response object. Options object controls
- 53:31Speaker 2: method header's, body, credentials, cash, mode, et CETERA response object
- 53:35Speaker 2: has methods to read the body response dot jason, response
- 53:38Speaker 2: dot text, response dot, blob, response dot orra buffer. You
- 53:41Speaker 2: check response dot OK or response dot status for success.
- 53:44Speaker 2: Handle's cores via options and server headers. Integrates with request
- 53:48Speaker 2: header's objects can be aborted using a board controller and
- 53:51Speaker 2: a bort signal. Can work with dreams. Integrates with the cache.
- 53:54Speaker 2: API caches for service workers. Far superior to XMLHTTP request.
- 53:59Speaker 1: Fetch sounds like the complete package. Web sockets for real
- 54:02Speaker 1: time communication.
- 54:03Speaker 2: New web socket are established as a persistent two way connection.
- 54:06Speaker 2: Ws dot, WS or WSS use eventhandlers dot on open
- 54:10Speaker 2: on message gets data in event dot data on air
- 54:13Speaker 2: on clothes send data with socket dot, send doses socket
- 54:16Speaker 2: dot close. Great for chat, live updates, multiplayer games. Doesn't
- 54:19Speaker 2: use ad event listener style. You assigned handlers.
- 54:21Speaker 1: Directly persistent connections, web storage, local storage, session storage.
- 54:25Speaker 2: Simple key value storage. In the browser. Local storage persists
- 54:29Speaker 2: across browser sessions. Same origin. Session storage allows only for
- 54:33Speaker 2: the current tab. Windows session both have set item key value,
- 54:36Speaker 2: remove item key clear length limits around five to ten
- 54:39Speaker 2: mil us storage event fires and other tabs. When storage
- 54:41Speaker 2: changes stores values is strings.
- 54:43Speaker 3: Simple key value stores.
- 54:45Speaker 1: Then for more complex data, index dB.
- 54:47Speaker 2: Yes INDEXTB is a full transactional NOSEQL database in the browser,
- 54:51Speaker 2: stores complex JavaScript objects, files, blobs, asynchronous API. You work
- 54:56Speaker 2: with databases object stores like tables, indexes for query transactions,
- 55:01Speaker 2: cursors for iteration. Open with index dB open name version,
- 55:05Speaker 2: schema changes happen in the unupgrade needed event powerful for
- 55:07Speaker 2: offline apps and large data sets.
- 55:09Speaker 1: A real database in the browser. Okay. Modules organizing code
- 55:12Speaker 1: ES modules versus the old module pattern.
- 55:15Speaker 2: Module pattern used iiv's enclosures to simulate modules. Es, modules,
- 55:19Speaker 2: import exports, script type module are the native standard, much
- 55:23Speaker 2: cleaner syntax, static analysis benefits, better dependency management. Named exports
- 55:28Speaker 2: export x inport x, default exports, export default y, import y,
- 55:31Speaker 2: dynamic import phrase incloading import maps for controlling resolution. The
- 55:35Speaker 2: modern standard.
- 55:35Speaker 1: Native modules are the way forward. Web workers background threads yes.
- 55:40Speaker 2: Run jas off the main UI thread to avoid blocking
- 55:42Speaker 2: dedicated workers. New worker for a single script, shared workers,
- 55:46Speaker 2: new shared worker accessible by multiple scripts same origin. Service
- 55:50Speaker 2: workers act as network proxies for offline support, push notifications,
- 55:53Speaker 2: et cetera. Communicate via post message and on message. Data
- 55:56Speaker 2: is copied, structured, cloning, or transfer transferable like a ray buffer.
- 56:01Speaker 2: Each worker type has different scope in life cycle.
- 56:03Speaker 1: Essential for performance parallelism in the browser. Important error handling
- 56:07Speaker 1: and debugging stayingsane.
- 56:10Speaker 2: Use try, dot, catch dot finally, throw errors with throw
- 56:13Speaker 2: new error or specific types type er, et cetera. Handle
- 56:16Speaker 2: global errors with window dot one, air, use browserdeb tools extensively,
- 56:21Speaker 2: console debugger breakpoints, stepping, network panel, static analysis linters. Typescript
- 56:27Speaker 2: helps catch errors early assertions can help during development. Robust
- 56:30Speaker 2: error handling is key.
- 56:31Speaker 1: Good practices are essential. Finally, json stringify.
- 56:35Speaker 2: And parse Gson does stringify value. Replacer space converts a
- 56:39Speaker 2: JS value to a JSON string. Json Dot parse text
- 56:43Speaker 2: Reviver parses a Jason string back into a JS value.
- 56:47Speaker 2: Replacer and reviver functions allow customization during serialization de serialization.
- 56:52Speaker 2: Space argument pritifies the string output ubiquitous for data exchange,
- 56:56Speaker 2: especially with apisvia.
- 56:57Speaker 1: Fetch perfect, and we covered fetch for the actual sending earlier.
- 57:00Speaker 2: Yep fetches how you typically get that Jason data from
- 57:03Speaker 2: a server?
- 57:04Speaker 1: Wo Okay. That was a seriously deep dive into JavaScript
- 57:07Speaker 1: and the web platform. It's a massive ecosystem.
- 57:10Speaker 2: It really is so many layers, from the core language
- 57:12Speaker 2: features to these incredibly powerful browser APIs, and they all interconnect.
- 57:16Speaker 1: Yeah, hopefully this gives you, our listener, a really solid
- 57:19Speaker 1: map of the territory, a framework for understanding how all
- 57:23Speaker 1: these pieces fit together in modern web development.
- 57:26Speaker 2: It's definitely a foundation you can build on whether you're
- 57:29Speaker 2: focusing on say React or view or maybe no JS
- 57:31Speaker 2: on the back end, or getting deep into specific APIs
- 57:35Speaker 2: like WebGL or web RTC.
- 57:36Speaker 1: And it just keeps changing, doesn't it. JavaScript and the
- 57:38Speaker 1: web platform are constantly evolving.
- 57:40Speaker 2: They really are. Which leads to a final thought, maybe,
- 57:43Speaker 2: given everything we've touched on today, this huge landscape, what's
- 57:47Speaker 2: the one area of JavaScript or the web platform that
- 57:49Speaker 2: really sparks your curiosity right now?
- 57:51Speaker 1: That's a great question for everyone listening to think about,
- 57:54Speaker 1: where do you want to explore next? Keep learning, keep building.
- 57:57Speaker 1: Thanks for joining us on the deep Dive