Latest / CyberSecurity Summary / You Don't Know JS: ES6 & Beyond
Transcript
- 0:00Speaker 1: Hey everyone, and welcome to another deep dive with us.
- 0:02Speaker 2: It's great to be here.
- 0:03Speaker 1: Today. We're taking a look at a book by Kyle
- 0:06Speaker 1: Simpson called You Don't Know JSES six and Beyond. Yeah, specifically,
- 0:10Speaker 1: we'll be focusing on the syntax and organization chapters to
- 0:14Speaker 1: see how they can help us write cleaner and more
- 0:16Speaker 1: modern JavaScript code.
- 0:18Speaker 2: Absolutely, two chapters packed with insights that can really level
- 0:22Speaker 2: up your JavaScript game.
- 0:23Speaker 1: Okay, So to kick things off, I think it's worth
- 0:25Speaker 1: highlighting the fact that JavaScript evolves so rapidly these days.
- 0:29Speaker 2: Right, oh yeah, definitely gone are the days of waiting
- 0:32Speaker 2: years for a new version.
- 0:34Speaker 1: Right.
- 0:35Speaker 2: ES six was a big shift, and the language is
- 0:37Speaker 2: constantly changing now, so it's really important for us the
- 0:40Speaker 2: developers to stay on top of things, always be learning,
- 0:43Speaker 2: right exactly, embrace the evolution.
- 0:45Speaker 1: Yeah, okay, So let's dive into some of these evolutionary changes,
- 0:48Speaker 1: starting with block scope declarations using let and constant sounds good. Now,
- 0:53Speaker 1: Before EES six we only had var, and I think
- 0:56Speaker 1: we've all run into some of those head scratching moments, right.
- 0:58Speaker 2: Well, for sure, var was function scoped, yeah, which you
- 1:02Speaker 2: know sometimes led to some confusing bugs.
- 1:04Speaker 1: Yeah, definitely especially in.
- 1:06Speaker 2: Larger projects where you might have variables with the same
- 1:09Speaker 2: name in different parts of the code.
- 1:10Speaker 1: Exactly. So how do let and constant address this?
- 1:14Speaker 2: Well, Let in constant introduced block level scoping mm hmmm,
- 1:19Speaker 2: which means they're only accessible within the block of code
- 1:22Speaker 2: where they're defined.
- 1:23Speaker 1: Okay, So it's all about creating these clear boundaries precisely.
- 1:26Speaker 2: Think of it as creating a more contained environment for
- 1:29Speaker 2: your variables, preventing those accidental collisions and unexpected behaviors.
- 1:33Speaker 1: Got it now? I noticed that Kyle Simpson is a
- 1:37Speaker 1: big advocate for declaring let at the top of the scope.
- 1:40Speaker 1: Why is that?
- 1:41Speaker 2: Yeah, he's got a strong point there. Declaring let at
- 1:43Speaker 2: the top makes it very clear what variables are in
- 1:46Speaker 2: play within that scope, and it helps avoid what's called
- 1:49Speaker 2: the temporal dead zone.
- 1:50Speaker 1: What's that?
- 1:51Speaker 2: It's an error you can run into if you try
- 1:53Speaker 2: to use a variable before it's been declared.
- 1:56Speaker 1: Ah. Okay, So it's like setting the ground rules up
- 1:58Speaker 1: front exactly.
- 1:59Speaker 2: It makes you code more predictable and less prone to errors.
- 2:02Speaker 1: Awesome. And what about const When should we use that?
- 2:05Speaker 2: Const is for values that you know won't change throughout
- 2:09Speaker 2: your code, like say the mathematical constant pi, right, or
- 2:13Speaker 2: maybe some configuration settings. Yeah, it makes it super clear
- 2:16Speaker 2: that those values are meant to be constant.
- 2:18Speaker 1: Makes sense. It's like a promise to yourself and your
- 2:20Speaker 1: fellow developers that this value is set in stone exactly.
- 2:24Speaker 2: Yeah. And there's a chance it might even help the
- 2:26Speaker 2: JavaScript engine optimize things behind the scenes.
- 2:29Speaker 1: Dot it so let for variables that might change cost
- 2:33Speaker 1: for rock solid values. Perfect, all right, Moving on to
- 2:36Speaker 1: something a bit more flexible now, the spread rest operator.
- 2:40Speaker 2: Ah, yes, the versatile operation.
- 2:43Speaker 1: It's like a Swiss army knife, right exactly.
- 2:45Speaker 2: It can do double duty, either spreading out the elements
- 2:47Speaker 2: of an iterable like an array, or gathering values into
- 2:51Speaker 2: an array.
- 2:52Speaker 1: It's like a transformer that can adapt to different situations.
- 2:54Speaker 2: I like that analogy. So, for example, imagine you have
- 2:57Speaker 2: an array of numbers and you want to pass them
- 2:59Speaker 2: as individual arguments to a function.
- 3:01Speaker 1: Right, which was a bit of a pain before sixty.
- 3:04Speaker 2: Exactly, you'd have to resort to tricks like using apply.
- 3:07Speaker 2: But with a spread operator, you can just use those
- 3:09Speaker 2: three dots boom, and it unpacks those array elements into
- 3:12Speaker 2: individual arguments, so much cleaner.
- 3:15Speaker 1: What about the rest operator, how does that work.
- 3:17Speaker 2: It's like the flip side of the coin. Instead of
- 3:19Speaker 2: spreading out, it gathers things together. Okay, let's say you
- 3:22Speaker 2: have a function that needs to handle an unknown number
- 3:25Speaker 2: of arguments. The rest operator lets you scoop them all
- 3:28Speaker 2: up into a nice need array.
- 3:30Speaker 1: So no more messing around with that clinky argument's objects.
- 3:33Speaker 2: Nope, the rest operator is much more elegant.
- 3:35Speaker 1: I'm sold now onto something that feels like a breath
- 3:39Speaker 1: of fresh air. Default parameter values, Oh yeah, those are great.
- 3:44Speaker 2: They might seem simple, but they really improve code clarity.
- 3:47Speaker 1: I know, right, I've written so much code over the
- 3:50Speaker 1: years checking for undefined values.
- 3:52Speaker 2: I feel you well. With default parameters, you can set
- 3:55Speaker 2: a default value right in the function definition.
- 3:57Speaker 1: It's like having a backup plan built in exactly.
- 4:00Speaker 2: If the caller doesn't provide a value, the default just
- 4:03Speaker 2: slides right in.
- 4:04Speaker 1: Love it. Now, what happens if someone passes in a
- 4:07Speaker 1: falsey value like zero or an empty string?
- 4:10Speaker 2: That's the beauty of it. Yeah, default parameters handle those
- 4:13Speaker 2: cases gracefully. They only kick in if the argument is
- 4:16Speaker 2: actually missing.
- 4:17Speaker 1: Ah, so it's not just a blind.
- 4:18Speaker 2: Replacement, right, It's smarter than that.
- 4:20Speaker 1: I like it, and we can even use more complex
- 4:23Speaker 1: expressions for default values.
- 4:24Speaker 2: Right, absolutely, any valid expression will do awesome.
- 4:28Speaker 1: Okay, I'm really starting to see how these seemingly small
- 4:32Speaker 1: changes really add up to make JavaScript more robust and expressive.
- 4:37Speaker 2: It's all about giving you more control and flexibility totally.
- 4:41Speaker 1: Now, let's talk about a feature that I find particularly elegant, destructuring.
- 4:46Speaker 2: Destructuring is all about taking complex data structures like arrays
- 4:50Speaker 2: and objects and extracting the values you need in a
- 4:52Speaker 2: very concise way.
- 4:53Speaker 1: It always looks so clean when I see it encode
- 4:55Speaker 1: it is.
- 4:56Speaker 2: Imagine you have an array representing a person's details like
- 4:59Speaker 2: their name, age, and occupation. With destructuring, you can pull
- 5:03Speaker 2: those values out into separate variables in a single line.
- 5:06Speaker 1: So instead of writing multiple lines to access each element,
- 5:09Speaker 1: it's all done in one go.
- 5:11Speaker 2: Exactly. Yeah, and it's even more interesting with object destructuring. Oh. Also,
- 5:15Speaker 2: you can extract properties from an object and assign them
- 5:18Speaker 2: to variables using a similar syntax. Okay, but what's cool
- 5:22Speaker 2: is that the target source pattern is reversed compared to
- 5:25Speaker 2: object literals.
- 5:27Speaker 1: Can you explain that a bit more sure?
- 5:29Speaker 2: In an object literal, you'd write property value, but with
- 5:34Speaker 2: destructuring its value variable. You're essentially specifying which property you
- 5:39Speaker 2: want and where you want to put it.
- 5:40Speaker 1: I see, it's like mirroring the structure of the object exactly.
- 5:44Speaker 2: And just like with default parameters, you can provide default
- 5:46Speaker 2: values in case a property is missing.
- 5:49Speaker 1: So it's a robust way to handle data.
- 5:51Speaker 2: Extraction absolutely, and we can even use destructuring and function parameters. Right.
- 5:55Speaker 1: It's a fantastic way to unpack arguments.
- 5:57Speaker 2: It makes your function definitions much more readable.
- 6:00Speaker 1: Love it all, right, onto some enhancements for our good friend,
- 6:04Speaker 1: the object literal.
- 6:05Speaker 2: Object Literal's got some cool upgrades in ES six, like
- 6:08Speaker 2: what Well. For one, we have concise methods, which provide
- 6:11Speaker 2: a shorter way to define functions within objects.
- 6:14Speaker 1: So less typing, more concise code exactly.
- 6:18Speaker 2: And then there are computed property names.
- 6:20Speaker 1: Ah, yes, I've seen those us.
- 6:22Speaker 2: They allow you to use expressions to determine the names
- 6:25Speaker 2: of properties dynamically.
- 6:26Speaker 1: Okay, that's pretty handy when you don't know the property
- 6:28Speaker 1: name in advance.
- 6:29Speaker 2: It is. It avoids that awkward bracket notation we used to.
- 6:33Speaker 1: Have to use much cleaner. And speaking of cleaner, let's
- 6:36Speaker 1: talk about string interpolation. I love how ES six made
- 6:40Speaker 1: working with strings so much easier.
- 6:42Speaker 2: Template literals are a game changer totally.
- 6:45Speaker 1: Using backticks, we can embed expressions directly into strings.
- 6:49Speaker 2: It's so much easier to read than concatenating strings.
- 6:51Speaker 1: Right, no more plus signs everywhere. But there's a catch, right,
- 6:55Speaker 1: something about them being plain strings.
- 6:57Speaker 2: Yeah, it's important to remember that template literals are immediately
- 7:00Speaker 2: evaluated into plan strings. There's no intermediate template object or
- 7:04Speaker 2: anything like that.
- 7:05Speaker 1: Got it, So it's more like an inline evaluation, kind
- 7:08Speaker 1: of like an ia.
- 7:09Speaker 2: That's a good way to think about it.
- 7:10Speaker 1: And multiline strings are a breeze with template literals too.
- 7:13Speaker 2: Right, absolutely, they preserve white space and line breaks as
- 7:17Speaker 2: you type them.
- 7:18Speaker 1: So much better than the old days of backslashes and
- 7:21Speaker 1: awkward line breaks.
- 7:22Speaker 2: No more string concatenation headaches.
- 7:24Speaker 1: Now onto a feature that sounds even more powerful, tagged
- 7:28Speaker 1: template literals.
- 7:30Speaker 2: Tag template literals takes string interpolation to the next level.
- 7:33Speaker 1: How sound.
- 7:34Speaker 2: You can attach a function a tag to a template literal,
- 7:38Speaker 2: and that tag function gets the string parts and values
- 7:41Speaker 2: as separate arguments. Okay, give you total control over how
- 7:44Speaker 2: the string is put together.
- 7:45Speaker 1: Wow, So you could write a tag function that say,
- 7:48Speaker 1: uppercases all the values or even does something more complex
- 7:51Speaker 1: like internationalization.
- 7:52Speaker 2: Exactly, the possibilities are pretty much endless.
- 7:55Speaker 1: That's awesome. Okay, Now onto a topic that's always a
- 7:58Speaker 1: bit of a hot potato. Erow functions.
- 8:01Speaker 2: Erofunctions are a concise way to write functions, but their
- 8:04Speaker 2: main claim to fame is how they handle.
- 8:07Speaker 1: This right, the dreaded this keyword.
- 8:10Speaker 2: They solve a lot of the headaches we used to
- 8:11Speaker 2: have with this binding.
- 8:13Speaker 1: Yeah, I've spent countless hours trying to wrangle this into submission.
- 8:17Speaker 2: I know the feeling. So with erofunctions, this is lexically bound.
- 8:21Speaker 2: It means that this always refers to the context where
- 8:24Speaker 2: the erowfunction was defined, not where it's called.
- 8:27Speaker 1: Oh I see, so no more var self.
- 8:29Speaker 2: This hacks exactly. Erofunctions make it much more predictable.
- 8:32Speaker 1: Awesome. But I've also heard that they're not always the
- 8:35Speaker 1: silver bullet. What are some of the caveats?
- 8:39Speaker 2: Well, they don't have their own arguments object okay, and
- 8:41Speaker 2: the way super works inside them is a bit.
- 8:43Speaker 1: Different too, So it's important to use them intentionally, mainly
- 8:46Speaker 1: for this binding behavior.
- 8:48Speaker 2: Yeah, they're a powerful tool, but like any tool, it's
- 8:51Speaker 2: good to know when and how to use it totally.
- 8:55Speaker 1: All right, let's move on to a feature that simplifies looping.
- 8:58Speaker 2: The four Ah yes, the four dot of loop is
- 9:03Speaker 2: a much cleaner way to iterate over iterable.
- 9:06Speaker 1: Objects compared to the old four loop with an index.
- 9:09Speaker 2: Yeah, or even the four dot N loop, which iterates
- 9:12Speaker 2: over object keys not values.
- 9:14Speaker 1: Right right, So it's like taking a scenic route through
- 9:16Speaker 1: an array, stopping at each value along the way.
- 9:19Speaker 2: I like that. It's a much more intuitive way to
- 9:22Speaker 2: work with iterables.
- 9:23Speaker 1: And speaking of iterables, can you remind me what those are? Exactly?
- 9:26Speaker 2: An interable is basically anything you can loop over arrays, strings, generators,
- 9:31Speaker 2: even some custom objects.
- 9:32Speaker 1: Okay.
- 9:33Speaker 2: The key is that they have a special method called
- 9:35Speaker 2: symbol dot iterator that defines how they should be iterated.
- 9:38Speaker 1: So for prew dot love works its magic by tapping
- 9:41Speaker 1: into that method.
- 9:42Speaker 2: Exactly. It's a very elegant solution.
- 9:44Speaker 1: I'm liking it.
- 9:45Speaker 2: Now.
- 9:45Speaker 1: What about those regular expression improvements?
- 9:48Speaker 2: Ah yes. ES six introduced two new flags for regular expressions,
- 9:54Speaker 2: the Unicode flag and the sticky flag.
- 9:57Speaker 1: Okay, Unicode, I get that. Yeah, we need to handle
- 10:00Speaker 1: emojis and other non asty characters these days, precisely.
- 10:03Speaker 2: The Unicode flag ensures that your regular expressions work correctly
- 10:07Speaker 2: with Unicode.
- 10:08Speaker 1: And what about the sticky flag. What does that do?
- 10:10Speaker 2: Sticky flag changes how the regular expression engine searches for matches. Okay,
- 10:14Speaker 2: it makes the engine stick to the current position in
- 10:17Speaker 2: the string, which is really helpful for certain parsing tasks.
- 10:20Speaker 1: Ah, I see, So it's like giving the rejects engine
- 10:22Speaker 1: a bit more context.
- 10:23Speaker 2: Exactly. It's a powerful tool for certain situations.
- 10:26Speaker 1: Awesome. Now onto some new editions that make working with
- 10:29Speaker 1: numbers and strings even more convenient.
- 10:32Speaker 2: EES six brought a bunch of new methods and features
- 10:35Speaker 2: for both number and string Okay, Like what for numbers,
- 10:38Speaker 2: we got new literal formats for binary, aucal and hexadecimal.
- 10:42Speaker 1: Numbers, so we can finally write binary numbers directly in
- 10:45Speaker 1: our code exactly.
- 10:47Speaker 2: And for strings, there's a whole suite of new methods
- 10:50Speaker 2: for handling Unicode characters, normalizing strings, and more.
- 10:54Speaker 1: It's like EES six is making JavaScript a first class
- 10:57Speaker 1: citizen in the world of Unicode.
- 10:59Speaker 2: It definitely is.
- 11:00Speaker 1: I'm all for it. Now, let's talk about something a
- 11:02Speaker 1: bit more mind bending. Symbols.
- 11:05Speaker 2: Symbols are a new primitive type in JavaScript. They're unique
- 11:09Speaker 2: and immutable. Okay, I'm falling so far, which makes them
- 11:12Speaker 2: perfect for creating hidden properties on objects.
- 11:16Speaker 1: Hidden properties. That sounds intriguing.
- 11:18Speaker 2: Imagine you're building a library and you need to store
- 11:20Speaker 2: some internal data on an object, but you don't want
- 11:23Speaker 2: to clash with any properties the user might be using.
- 11:25Speaker 2: I see, symbols allow you to create these properties that
- 11:28Speaker 2: are essentially invisible to the outside world.
- 11:30Speaker 1: So it's like having a secret compartment in your objects exactly.
- 11:34Speaker 2: It's a great way to improve encapsulation and prevent naming collisions.
- 11:38Speaker 1: And because symbols are unique, there's no chance of accidentally
- 11:41Speaker 1: using the same symbol twice.
- 11:42Speaker 2: Precisely, they offer a level of safety and control that
- 11:45Speaker 2: we didn't have before.
- 11:46Speaker 1: That's really neat. Okay, Now let's dive into the world
- 11:49Speaker 1: of iterators and generators.
- 11:51Speaker 2: Iterators and generators are all about controlling the flow of data. Okay.
- 11:55Speaker 2: An iterator is an object that defines a sequence of values, right,
- 11:59Speaker 2: and generator is a special kind of function that can
- 12:02Speaker 2: be paused and resumed producing a sequence of values.
- 12:05Speaker 1: Oh, I think I need an analogy here. This sounds
- 12:07Speaker 1: a bit abstract.
- 12:08Speaker 2: Imagine you're reading a book, and you want to be
- 12:11Speaker 2: able to pause at any point and come back later
- 12:14Speaker 2: without losing your place. Okay, generators are kind of like
- 12:17Speaker 2: bookmarks for your code.
- 12:19Speaker 1: I like that. So using the yield keyword in a
- 12:22Speaker 1: generator is like placing a bookmark exactly, and.
- 12:25Speaker 2: The generator function can pick up right where it left off.
- 12:28Speaker 1: That's really cool. And how are generators related to iterators?
- 12:32Speaker 2: The generator function actually creates an iterator. When you call
- 12:37Speaker 2: a generator function, it doesn't run the code right away. Oh, Instead,
- 12:41Speaker 2: it returns an iterator object, and each time you call
- 12:44Speaker 2: the next method on that iterator, it runs the generator
- 12:48Speaker 2: function until it hits a yield statement.
- 12:50Speaker 1: So it's like stepping through the generator function one bookmark at.
- 12:52Speaker 2: A time, precisely.
- 12:54Speaker 1: I see how this could be really useful for things
- 12:56Speaker 1: like asynchronous operations.
- 12:58Speaker 2: You're right, generators provide a very elegant way to handle
- 13:02Speaker 2: a secretous code, especially when combined with promises.
- 13:05Speaker 1: Okay, my mind is officially blown. All right, let's shift
- 13:08Speaker 1: gears and talk about one of the most anticipated features
- 13:11Speaker 1: of ES six. Modules.
- 13:13Speaker 2: Ah. Yes, modules finally a standardized way to organize our code.
- 13:18Speaker 1: It's like JavaScript finally grew up.
- 13:19Speaker 2: I know, right before EES six we had to rely
- 13:22Speaker 2: on all sorts of ad hoc solutions for modularity, right, all.
- 13:25Speaker 1: Those different module loaders and bundlers exactly.
- 13:28Speaker 2: But now we have a built in way to define
- 13:30Speaker 2: modules in important export code.
- 13:32Speaker 1: No more global scope pollution exactly.
- 13:35Speaker 2: Modules make it so much easier to write well structured
- 13:37Speaker 2: and maintainable code.
- 13:39Speaker 1: It's a beautiful thing. Now let's talk about a feature
- 13:42Speaker 1: that might be familiar to developers coming from other languages.
- 13:46Speaker 2: Classes.
- 13:47Speaker 1: Classes in ES six provide a more familiar syntax for
- 13:50Speaker 1: working with objects and inheritance.
- 13:53Speaker 2: So under the hood, it's still prototypes.
- 13:55Speaker 1: That's right. Classes are basically syntactic sugar on top of prototypes, so.
- 14:00Speaker 2: They're not a completely new inheritance model.
- 14:03Speaker 1: Nope. They just offer a cleaner way to express what
- 14:05Speaker 1: we were already doing.
- 14:07Speaker 2: Okay, So it's all about making the code more readable
- 14:10Speaker 2: and easier to understand.
- 14:12Speaker 1: Exactly, especially for those coming from class based languages.
- 14:15Speaker 2: Right, and classes come with all the usual bells and whistles, constructors, methods,
- 14:19Speaker 2: the extends, keyword.
- 14:21Speaker 1: You got it. They just make things a bit smoother.
- 14:23Speaker 2: I'm all for smoother, all right, Onto some new additions
- 14:26Speaker 2: for handling data, maps, sets, and weak references.
- 14:31Speaker 1: Maps and sets provide more efficient ways to work with
- 14:33Speaker 1: key value pairs and unique values.
- 14:35Speaker 2: Okay, can you give me an example.
- 14:37Speaker 1: Imagine you're building a shopping cart. You could use a
- 14:39Speaker 1: map to store the items in the cart, right, where
- 14:41Speaker 1: the key is the product ID and the value is
- 14:44Speaker 1: the quantity I see.
- 14:45Speaker 2: And if you need to keep track of unique visitors
- 14:47Speaker 2: to your website, you could use a set to store
- 14:50Speaker 2: their user IDs.
- 14:51Speaker 1: Ah, makes sense? And what about weak references.
- 14:54Speaker 2: Weak references are a way to hold a reference to
- 14:56Speaker 2: an object without preventing it from being garbage collected.
- 15:00Speaker 1: Interesting, So it's like having a loose grip on an
- 15:02Speaker 1: object exactly.
- 15:03Speaker 2: It's useful for situations where you want to associate data
- 15:06Speaker 2: with an object without affecting its lifespan.
- 15:09Speaker 1: Got it. Okay, so we've covered a lot of ground
- 15:11Speaker 1: here in this first part.
- 15:12Speaker 2: We have.
- 15:13Speaker 1: We've seen how ES six introduced block scope declarations, the
- 15:16Speaker 1: spreadurist operator, default parameter values, and destructuring.
- 15:20Speaker 2: And we've also looked at object literal enhancements, tablet literals, aerofunctions,
- 15:25Speaker 2: and the four dot of loop.
- 15:26Speaker 1: Plus those handy new methods for numbers and strings the
- 15:29Speaker 1: power symbols, and the control offered by iterators and generators.
- 15:33Speaker 2: We've even touched on modules, classes, and the data handling
- 15:36Speaker 2: capabilities of maps, sets and weak references.
- 15:39Speaker 1: It's a lot to take in before we move on
- 15:41Speaker 1: to what lies beyond YES six. I encourage everyone to
- 15:44Speaker 1: think about which of these features you're most excited to
- 15:46Speaker 1: try out in your own projects.
- 15:48Speaker 2: There's so much to explore and experiment with in the
- 15:51Speaker 2: world of modern JavaScript, and stay tuned for Part two,
- 15:55Speaker 2: where we'll venture beyond ES six and into even more
- 15:58Speaker 2: exciting territory.
- 15:59Speaker 1: It's going to be a wild ride, all right. So
- 16:02Speaker 1: we've explored a lot of the core features of ES six.
- 16:05Speaker 2: Yeah, we've covered a good chunk of it.
- 16:06Speaker 1: Now I'm really curious to see what lies beyond ES six.
- 16:09Speaker 2: Buckle up, there's a whole lot more to discover.
- 16:12Speaker 1: Okay, so where do we start.
- 16:14Speaker 2: Well, one of the most anticipated features beyond ES six
- 16:17Speaker 2: is asyncowate. It's all about making asynchronous code look and
- 16:21Speaker 2: feel more like synchronous code.
- 16:23Speaker 1: Oh that sounds like a dream come true. I've spent
- 16:26Speaker 1: countless hours wrestling with callbacks and promises.
- 16:28Speaker 2: I know, right, asyncowight really simplifies things.
- 16:32Speaker 1: Okay, so how does it actually work.
- 16:33Speaker 2: Imagine you're fetching data from an API with promises, you
- 16:37Speaker 2: typically have these chains of than handlers. Yeah, but with
- 16:40Speaker 2: a syncowate you can write code that reads more like
- 16:42Speaker 2: a traditional synchronous flow.
- 16:44Speaker 1: So no more pyramid of doom exactly.
- 16:47Speaker 2: You use the awake keyword to pause execution until a
- 16:49Speaker 2: promise is resolved.
- 16:51Speaker 1: And that makes the code much easier to read and understand.
- 16:53Speaker 2: Absolutely, asynchronous code becomes much less daunting.
- 16:57Speaker 1: I'm sold. Now what about object dot observe. I heard
- 17:01Speaker 1: that was supposed to be a game changer for change detection. Ah.
- 17:04Speaker 2: Yes, Object dot observe was a promising feature. It allowed
- 17:07Speaker 2: you to observe changes to JavaScript objects and get notified
- 17:11Speaker 2: when properties were added, deleted, or modified.
- 17:14Speaker 1: Sounds incredibly useful for things like data binding.
- 17:17Speaker 2: It did. Yeah, Unfortunately it was eventually deprecated due to
- 17:20Speaker 2: performance concerns and some complexities. Oh that's a shame, it is.
- 17:24Speaker 2: But the good news is that proxies can be used
- 17:26Speaker 2: to achieve similar functionality with more control and flexibility.
- 17:31Speaker 1: Right, we talked about proxies earlier. Okay, so they kind
- 17:33Speaker 1: of stepped in to fill.
- 17:34Speaker 2: The gap yep proxies are super powerful.
- 17:36Speaker 1: Now let's talk about some simpler additions that make life easier,
- 17:40Speaker 1: like the exponentiation operator.
- 17:42Speaker 2: Oh yeah, that's a handy one. No more math dot
- 17:43Speaker 2: pal for simple exponentiation.
- 17:46Speaker 1: Much more concise. And what about spread syntax for objects?
- 17:50Speaker 1: I loved using it with a raise.
- 17:52Speaker 2: Well you're in luck. Spread syntax can now be used
- 17:54Speaker 2: to copy properties from one object to another.
- 17:57Speaker 1: Awesome, so we can finally say goodbye to manually copying properties.
- 18:01Speaker 2: It's a huge time saver.
- 18:02Speaker 1: And while we're on the topic of handy additions, let's
- 18:05Speaker 1: not forget about array dot includes.
- 18:08Speaker 2: Array dot includes makes it super easy to check if
- 18:10Speaker 2: an array contains a certain value.
- 18:12Speaker 1: No more writing custom loops or helper functions for that.
- 18:15Speaker 2: It's the little things that make life easier totally.
- 18:19Speaker 1: Now let's talk about something that sounds a bit more advanced. CMD.
- 18:23Speaker 2: CMD stands for single instruction, multiple data. It's a way
- 18:28Speaker 2: to perform parallel processing.
- 18:30Speaker 1: Okay, so instead of processing data one element at a time,
- 18:33Speaker 1: we can process multiple elements simultaneously exactly.
- 18:37Speaker 2: It can lead to some serious performance games, especially for
- 18:40Speaker 2: tasks that involve a lot of number crunching.
- 18:42Speaker 1: Like image or audio processing exactly.
- 18:45Speaker 2: CMD is a game changer for those kinds of applications.
- 18:48Speaker 1: It's like having a team of processors working together instead
- 18:51Speaker 1: of just one.
- 18:52Speaker 2: It really is. It opens up a whole new level
- 18:54Speaker 2: of performance for JavaScript.
- 18:56Speaker 1: I'm impressed JavaScript keeps getting more and more.
- 18:58Speaker 2: Powerful, and it's doing it without sacrificing its accessibility and
- 19:02Speaker 2: developer friendliness.
- 19:03Speaker 1: That's the beauty of it. It's evolving but staying true
- 19:06Speaker 1: to its roots.
- 19:07Speaker 2: Well said.
- 19:07Speaker 1: Okay, before we move on to the final part of
- 19:09Speaker 1: our deep dep I want to shift gears and talk
- 19:11Speaker 1: about something a bit different. Type to Raise.
- 19:14Speaker 2: Ah. Yes, Type to Raise. They're like stepping into the
- 19:17Speaker 2: engine room of JavaScript in what sense they allow you
- 19:20Speaker 2: to work with raw binary data in a very structured
- 19:24Speaker 2: and efficient way.
- 19:25Speaker 1: Okay, now this is starting to sound a bit intimidating.
- 19:27Speaker 1: I usually think of JavaScript as dealing with strings, numbers,
- 19:31Speaker 1: and objects.
- 19:32Speaker 2: It is a bit of a shift. Yeah, but think
- 19:33Speaker 2: about scenarios where you need to process large files, manipulate images,
- 19:38Speaker 2: or work with audio data.
- 19:39Speaker 1: Those are definitely more specialized use cases.
- 19:42Speaker 2: They are, but they're becoming more and more common in
- 19:44Speaker 2: web development.
- 19:45Speaker 1: I see and type to rays provide a way to
- 19:48Speaker 1: handle those kinds of tasks more efficiently.
- 19:50Speaker 2: Exactly. They act as a bridge between JavaScript's high level
- 19:54Speaker 2: world and the low level world of binary data.
- 19:57Speaker 1: So it's like giving JavaScript access to the materials.
- 20:00Speaker 2: Precisely. It opens up a whole new level of control
- 20:03Speaker 2: and performance.
- 20:04Speaker 1: Okay, So I'm guessing there's more to type arrays than
- 20:06Speaker 1: just arrays of ones and zeros. What makes them special?
- 20:09Speaker 2: Type arrays offer a way to view that binary data
- 20:13Speaker 2: as different types, like integers, floats, or even custom data structures.
- 20:18Speaker 1: So we can interpret that raw binary data in different ways.
- 20:22Speaker 2: Exactly. It's like looking at the same data through different lenses.
- 20:25Speaker 1: And that gives us more control over how we process
- 20:27Speaker 1: it exactly.
- 20:29Speaker 2: Now, the actual binary data is stored in an array buffer.
- 20:32Speaker 2: What's bad, it's basically a raw block of memory.
- 20:35Speaker 1: Okay.
- 20:35Speaker 2: Type rays don't actually store the data themselves. They just
- 20:38Speaker 2: provide a way to access and interpret that data within
- 20:41Speaker 2: the array buffer.
- 20:42Speaker 1: So the array buffer is like the container, and the
- 20:44Speaker 1: type array is like the map that tells us what's inside.
- 20:48Speaker 2: That's a good way to think about it, And.
- 20:49Speaker 1: We can have multiple type derays viewing the same array buffer.
- 20:52Speaker 2: Absolutely each type array provides a different view of the
- 20:55Speaker 2: same underlying data.
- 20:56Speaker 1: That's pretty powerful. Now, working with binary data can be tricky.
- 21:01Speaker 1: Are there any gotchas we should be aware of?
- 21:03Speaker 2: Definitely. One thing to be mindful of is indianness.
- 21:06Speaker 1: Indian Ness I've heard the term, but never really understood
- 21:09Speaker 1: what it means.
- 21:10Speaker 2: It refers to the order in which bytes are stored
- 21:12Speaker 2: in memory. Oka Some systems store the most significant bite first,
- 21:16Speaker 2: big Indian, while others store the least significant bite first,
- 21:20Speaker 2: little Indian.
- 21:21Speaker 1: So it's like writing a number from left to right
- 21:23Speaker 1: or right to left exactly.
- 21:25Speaker 2: It can affect how we interpret.
- 21:26Speaker 1: The data, and JavaScript provides ways to handle that.
- 21:29Speaker 2: Yes, we can detect and handle indian ness to make
- 21:32Speaker 2: sure we're reading the data correctly.
- 21:34Speaker 1: Okay, good to know. Now I'm curious about practical applications.
- 21:38Speaker 1: Can you give me some real world examples of how
- 21:41Speaker 1: type rays are used?
- 21:42Speaker 2: Sure, Image processing is a common use case. Image data
- 21:46Speaker 2: is basically a grid of pixels, each represented by color values.
- 21:50Speaker 2: Type arrays can be used to manipulate those pixel values directly,
- 21:54Speaker 2: allowing for things like brightness adjustments, color transformations, and even
- 21:58Speaker 2: image compression.
- 21:59Speaker 1: Wow, can do some serious image manipulation with JavaScript now.
- 22:02Speaker 2: Absolutely, and because type derays offer efficient access to the data,
- 22:07Speaker 2: they're great for performance critical tasks.
- 22:09Speaker 1: What other examples can you think of?
- 22:11Speaker 2: Audio processing is another big one. Audio data is represented
- 22:15Speaker 2: as a series of samples. Type derays can be used
- 22:18Speaker 2: to analyze and manipulate those samples, enabling things like filtering, equalization,
- 22:24Speaker 2: and even audio synthesis.
- 22:26Speaker 1: That's amazing. So we can create our own audio effects
- 22:29Speaker 1: using JavaScript.
- 22:30Speaker 2: You got it. And because tuch derays are so efficient,
- 22:33Speaker 2: we can even do real time audio manipulation.
- 22:36Speaker 1: This is starting to sound a bit like the realm
- 22:39Speaker 1: of low level languages like C or C plus plus
- 22:43Speaker 1: our type derays really meant for the average JavaScript developer.
- 22:46Speaker 2: They are a more specialized feature, but understanding the basics
- 22:50Speaker 2: can be beneficial even if you don't use them directly.
- 22:52Speaker 1: So it's good to have them in our mental toolkit exactly.
- 22:55Speaker 2: It broadens our understanding of how JavaScript works under the hood.
- 22:58Speaker 1: Okay, so we've talked about type derays providing different views
- 23:01Speaker 1: of binary data, but how do we actually create those views.
- 23:05Speaker 2: It's a two step process. First, you create an array buffer,
- 23:08Speaker 2: which is that raw memory buffer, right, and then you
- 23:10Speaker 2: create a type array view on top of that buffer,
- 23:13Speaker 2: specifying the type and size of the view.
- 23:15Speaker 1: So the array buffer is like the canvas and the
- 23:17Speaker 1: type deray is like the paintbrush.
- 23:19Speaker 2: I like that analogy. The type ray doesn't copy the data,
- 23:22Speaker 2: it just provides a way to access it.
- 23:24Speaker 1: So if we change the data through one view, those
- 23:26Speaker 1: changes will be reflected in other views that share the
- 23:29Speaker 1: same array buffer.
- 23:30Speaker 2: Exactly, it's all connected.
- 23:31Speaker 1: What are some of the different types of views we
- 23:33Speaker 1: can create?
- 23:34Speaker 2: There are a bunch of type ray constructors, each representing
- 23:37Speaker 2: a different way to view the data.
- 23:38Speaker 1: Okay, like what you've got.
- 23:39Speaker 2: Any array for signed eight bit integers, u inate array
- 23:43Speaker 2: for unsigned eight bit integers, in sixteen array for signed
- 23:46Speaker 2: sixteen bit integers, and so on. Okay, And they're also
- 23:49Speaker 2: float thirty two array and float sixty four array for
- 23:52Speaker 2: floating point numbers.
- 23:53Speaker 1: So we have a lot of options depending on the
- 23:55Speaker 1: kind of data we're working with.
- 23:56Speaker 2: Exactly, choose the right tool for.
- 23:58Speaker 1: The job, and don't forget typed arrays are also iterable,
- 24:02Speaker 1: that's right.
- 24:02Speaker 2: We can use them with four to sea of loops
- 24:04Speaker 2: and other iteration techniques.
- 24:06Speaker 1: It's all coming together. Well. I think we've covered a
- 24:09Speaker 1: lot of ground. In this second part, we've gone from
- 24:11Speaker 1: a sincawight to object dot observe to typed rays.
- 24:16Speaker 2: We've really explored some of the cutting edge features of JavaScript.
- 24:19Speaker 1: What I find really amazing is how JavaScript is managing
- 24:22Speaker 1: to evolve and become more powerful without sacrificing its core
- 24:26Speaker 1: values of accessibility and developer friendliness.
- 24:29Speaker 2: I agree, it's a testament to the careful design and
- 24:33Speaker 2: evolution of the language.
- 24:34Speaker 1: Now, before we jump into the final part of our
- 24:36Speaker 1: deep dive, I want to leave everyone with a thought
- 24:38Speaker 1: provoking question. What does this rapid evolution of JavaScript mean
- 24:43Speaker 1: for the future of web development? How will these advancements
- 24:46Speaker 1: shape the way we build websites and web applications in
- 24:49Speaker 1: the years to come? All right, welcome back to the
- 24:52Speaker 1: final stretch of our deep dive into ES six and beyond.
- 24:56Speaker 1: We've covered a lot of ground.
- 24:57Speaker 2: We have, from the foundational features of ESA to some
- 25:00Speaker 2: of the more specialized areas exactly.
- 25:03Speaker 1: Now, for this last part, I'm kind of curious to
- 25:04Speaker 1: see how some of these pieces fit together. We've talked
- 25:07Speaker 1: about typed arrays for efficient binary data handling, and maps
- 25:12Speaker 1: and sets for managing collections. How do these powerful tools
- 25:15Speaker 1: work together because they seem kind of like they're in
- 25:17Speaker 1: different worlds.
- 25:18Speaker 2: Yeah, yeah, that's a great point. It might seem that way,
- 25:20Speaker 2: but they can actually complement each other really well. Okay,
- 25:22Speaker 2: So well, let's imagine you're building a game and you
- 25:27Speaker 2: need to represent the game world as a grid, right, okay, yeah, yeah,
- 25:32Speaker 2: each cell and that grid could be represented by a
- 25:35Speaker 2: thirty two bit integer, which you could store in a
- 25:38Speaker 2: un thirty two array. All right, Now, let's say you
- 25:40Speaker 2: want to store additional information about each cell, like the
- 25:43Speaker 2: type of terrain or whether it's occupied by a player.
- 25:46Speaker 2: You could use a map where the keys are the
- 25:49Speaker 2: cell indices from the un thirty two array, and the
- 25:52Speaker 2: values are objects containing those extra details.
- 25:55Speaker 1: So instead of using like nested arrays or objects, which
- 25:57Speaker 1: can get kind of messy, we have this more struct
- 26:00Speaker 1: shirt approach using type arrays in.
- 26:02Speaker 2: A map exactly. You get the efficiency of type arrays
- 26:05Speaker 2: for the grid data itself and the flexibility of a
- 26:07Speaker 2: map for associating additional information.
- 26:10Speaker 1: And I imagine this would scale really well for large
- 26:12Speaker 1: game worlds.
- 26:13Speaker 2: Absolutely. It's a great way to manage large data sets efficiently.
- 26:16Speaker 1: That's cool. Any other applications come to mind? Where you
- 26:18Speaker 1: might combine type arrays with maps or sets.
- 26:21Speaker 2: Hmm, let's see what about scientific computing, Like if you're
- 26:26Speaker 2: working with matrices or vectors, Okay, yeah, you could use
- 26:28Speaker 2: type arrays to represent those mathematical structures and then use
- 26:32Speaker 2: sets to efficiently perform set operations like union, intersection and difference.
- 26:38Speaker 1: So we're leveraging the numerical power of type arrays and
- 26:41Speaker 1: the set operations of sets to do some pretty complex calculation.
- 26:45Speaker 2: Precisely, it's all about choosing the right tool for the
- 26:48Speaker 2: job and combining them in clever ways.
- 26:51Speaker 1: I'm really seeing the power and flexibility of JavaScript here.
- 26:55Speaker 2: It's a versatile language for sure.
- 26:57Speaker 1: Now, before we wrap things up, I think it's where
- 27:00Speaker 1: noting that while type dearrays are awesome, yeah, they're not
- 27:03Speaker 1: always the right choice, right. They do add a level
- 27:05Speaker 1: of complexity, definitely.
- 27:07Speaker 2: Yeah. If you're working with smaller data sets or your
- 27:10Speaker 2: application doesn't have strict performance requirements, then traditional arrays and
- 27:14Speaker 2: objects might be a simpler and more suitable option.
- 27:17Speaker 1: It's all about choosing the right tool for the job.
- 27:19Speaker 1: As always.
- 27:20Speaker 2: Couldn'tgree more.
- 27:21Speaker 1: Well, I think we've done a pretty good job of
- 27:22Speaker 1: exploring the world of ES six and beyond. We've covered
- 27:25Speaker 1: the core features, delved into some specialized areas like type derays.
- 27:30Speaker 2: Yeah, we've seen how JavaScript is constantly evolving to meet
- 27:32Speaker 2: the demands of modern web development.
- 27:35Speaker 1: What I find really fascinating is how it's embracing new
- 27:39Speaker 1: paradigms while still staying true to its roots of accessibility
- 27:43Speaker 1: and developer friendliness.
- 27:44Speaker 2: It's an exciting time to be a JavaScript developer. There's
- 27:47Speaker 2: always something new to learn, something new to try.
- 27:49Speaker 1: It's a language that keeps pushing the boundaries of what's
- 27:52Speaker 1: possible on the web.
- 27:53Speaker 2: Absolutely, so keep.
- 27:54Speaker 1: Experimenting, keep learning, and most importantly, have fun coding. That's
- 27:59Speaker 1: what it's all.
- 27:59Speaker 2: About out couldn't to said it better myself.
- 28:02Speaker 1: Well, that's all the time we have for today. Thanks
- 28:04Speaker 1: for joining us on this deep dive into the world
- 28:06Speaker 1: of ES six and beyond.