Pages

Thursday, March 14, 2019

Javascript for/in for/of forEach and for(;;)

Javascript has different variants of iteration with different feature. Below is a summary of different for loop iteration with their features:



For /in
For / of
Obj.forEach
Traditional for
Object Key type
All (numeric + non-numeric)
Numeric only
Numeric only
Numeric only
Index vs Value
Index only
Value only

To get index Array#entries()
Index + Value 

Index as the second param of callback fn
Index only
Empty element
const arr = ['a',, 'c'];

Ignore empty element
Consider empty element
Ignore empty element
Consider empty element
Function Context (context of this )
this of the outer context
this of the outer context
Own version of
this
this of the outer context
Async / Await + Generator

Yes
Y
With caveats and not straight forward
Y

Side topics emerged here:
Ø  ESLint
Ø  Generator
Ø  Yield
Ø  Async / Await

Source and Details: here


No comments :

Post a Comment