Array.prototype.reduce: This function is also known as "fold" in other languages. It allows you to given an array, return a new value from it by "reducing/folding" all its items to it. Here's an example:
constnumbers=[1,2,3,4];constnumbersTotal=numbers.reduce((total,current)=>total+current);// The callback function of `reduce` receives the total so far, and the current// item, so this is what happens in every iteration://// 0: total = 1, current = 2 ... so total + current = 3// 1: total = 3 (from the result of the previous iteration), current = 3. 3 + 3 = 6// 2: total = 6 (again, from the previous iteration), current = 4. 6 + 4 = 10//// Final result = 10
Nullish coalescing: Is a new operator expressed with two question marks (??). It goes to the value of the right ONLY if the value on the left is nullish (either null or undefined):
0??"right value";// 0false??"right value";// falsenull??"right value";// "right value"undefined??"right value";// "right value"// Compared to the previous "falsy" approach using `||`, which sucks:0||"right value";// "right value"false||"right value";// "right value"null||"right value";// "right value"undefined||"right value";// "right value"
Spread: Another operator, this one is expressed with an ellipsis (3 dots: ...), and is used to "spread" values of an array, string and other iterators in place of arguments:
constnumbers=[1,2,3,4];constmaxNumber=Math.max(...numbers);// This is like doing: Math.max(1, 2, 3, 4);
Thanks bro , it would be much better if you add examples also
Here you go:
Array.prototype.reduce
: This function is also known as "fold" in other languages. It allows you to given an array, return a new value from it by "reducing/folding" all its items to it. Here's an example:More info here.
for...of
: Is just a better way of looping withfor
over something:More info here.
??
). It goes to the value of the right ONLY if the value on the left is nullish (eithernull
orundefined
):More info here.
...
), and is used to "spread" values of an array, string and other iterators in place of arguments:More info here.
Object.entries
: One of the best ways of looping over an object. It takes an object and returns an array with[key, value]
tuples:More info here.
Cheers!
Thank you! 😊