Alagarasan Profile picture
Jan 28 9 tweets 8 min read
Generator function* in JavaScript:

A thread 🧵

#100DaysOfCode #javascript #Angular #reactjs #devbubble
In JavaScript, generator functions are a special type of function that allows you to use the yield keyword to pause and resume the execution of the function.

#100DaysOfCode #NodeJS #CodeLife
They allow you to create iterators, which are objects that can be used to iterate over a sequence of values.

A generator function is defined using the function* keyword and can be invoked using the yield keyword.

#100daysofcodechallenge #NodeJS #reactjs
For example, here is a simple generator function that yields the numbers from 0 to 4:

You can create an iterator from the generator function by calling it with the Symbol.iterator method.

#100DaysOfCode #javascript #reactjs #Angular #NodeJS #js #webdevelopment Generator function* in JS
You can then use the next() method of the iterator to get the next value.

OR

You can also use the for...of loop to iterate over the values.

#100DaysOfCode #reactjs #Angular #NodeJS #js
One of the main advantages of generator functions is that they allow you to create iterators that can be paused & resumed.

#Angular #reactjs #NodeJS #javascript
This can be useful for situations where you need to generate large amounts of data, or where you need to work with data that is generated on-the-fly.

I'll share more about the generator function's uses and use cases in my upcoming threads.

#100DaysOfCode #reactjs #nodejs
Let me know in the comments if you have any questions.

If you enjoyed this thread, kindly RT🔁 the first tweet.

This account exists to help you:
- Learn & revamp your web-dev skills

Follow🏃 @AlagarasanWDev ... let's learn together.

That's a wrap!
❤️
Cheers!

#techtwitter
@threadreaderapp Please unroll

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Alagarasan

Alagarasan Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @AlagarasanWDev

Jan 27
Memoization: Using Proxy in JavaScript

#100DaysOfCode #javascript #rarely_used #devbubble
Memoization is a technique used to optimize the performance of a function by caching its results for a given set of inputs.

#100DaysOfCode #reactjs #Angular #NodeJS
The idea is that if a function is called multiple times with the same input, it's more efficient to return the cached result instead of re-computing the result each time.

#100daysofcodingchallenge #reactjs #Angular #NodeJS
Read 9 tweets
Jan 26
Data virtualization: With Proxies in JavaScript.

A thread 🧵

#100DaysOfCode #javascript #rarely_used #devbubble
Data virtualization using Proxies in JavaScript refers to the ability to create virtualized data structures, such as virtualized arrays, that load their data on demand rather than loading all data at once.

#100DaysOfCode #ReactJS #Angular
This can be useful for improving the performance of an application when working with large data sets.

In this Eg., we create a VirtualArray class that takes in two args- the length of the array & a loader function.

#100DaysOfCode #javascript #NodeJS #ReactJs #Angular #devbubble Proxy - VirtualArray in JS
Read 8 tweets
Jan 18
WeakMap in JavaScript

A thread 🧵

#100DaysOfCode #javascript #rarely_used
A WeakMap is a map that holds weak references to its keys.

This means that the keys are eligible for garbage collection if there are no other references to them.

This feature can be useful for implementing caches or other similar data structures.

#reactjs #Angular #NodeJS #js
A WeakMap is a special kind of map where keys must be objects and the map doesn't prevent garbage collection of its keys.

You can think of a WeakMap as a map that doesn't "own" its keys, and therefore doesn't keep them alive.

#100daysofcodechallenge #100DaysOfCode
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(