|
This should test your understanding of falsy and truthy numbers in JavaScript 👇 |
|
|
Featured content |
|
JavaScript has come a long way in the past 10 years with brand new feature upgrades in each one. |
Let's look at the 5 most significant features that arrived in ES9; and see the ones you missed. |
|
Async generators was a powerful one from ES9. |
Just like normal generators but now it pops out the values after asynchronous work like a network request or something: |
|
So when we call .next() we'll get a Promise: |
|
It's such a powerful tool for streaming data in web app in a structured + readable manner — just look at this function that buffers and streams data for a video-sharing app like YouTube: |
|
And now to consume this generator we'll use for await of -- async iteration: |
|
I wonder if the actual YouTube JavaScript code uses generators like this? |
|
When I use String.raw I'm saying: Just give me what I give you. Don't process anything. |
Leave those escape characters alone: |
|
No more escaping backslashes: |
|
We can write: |
|
Perfect for writing regexes with a stupid amount of these backslashes: |
Something like this but much worse: |
From this✅: |
|
To this ✅: |
|
So "raw" as in unprocessed. |
|
|
|
It's one of those "cool" things you can do in JavaScript that are immensely powerful when put to good use. |
|
|
|
A is ongoing but the user wants to do B but A needs to happen first. |
Example: Social app where users can create, save, and publish posts. Like Medium. |
|
What if the user wants to publish the post when it's saving? |
Solution: Ensure the post saves before publishing happens, by resolving promise from outside. |
|
|
Don't let the bugs byte, Tari Ibaba |
0 Komentar untuk "Transformative ES9 JS features: async generators, String.raw, +3 more"