Photo by Christopher Robin Ebbinghaus on Unsplash


Variable hoisting is one of the simplest but still misunderstood concepts in JavaScript. There are still a few of us who feel that in Javascript variable declaration is physically moved to the top of the function block. Although conceptually it is much simpler to visualize and understand the variable being physically moved to the top, that is not how it happens.

Let's understand this with an example, consider the code below

Understanding the output

The simple way: The variable declarations are hoisted, and that essentially means…

Photo by ERNEST TARASOV on Unsplash


As the name suggests, an iterator is an object which allows you to iterate on itself by implementing the iterator protocol (by implementing the next() method). The next method in the protocol returns an object with two properties:

value: the next value in the sequence

done: a boolean value to indicate if we are done traversing the sequence

Once we iterate through an iterator it is not possible to iterate again because additional calls to the next() method will return {done: true}. Once traversed completely, iterators are said to be completely consumed as the iteration can be done only once.


Gaurav Awale

Sr. Software Developer at SpringerNature Technology and Publishing Solutions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store