13 October, 2020
Guide Fari
TIL(Tuesday 13 October 2020)
Twitter can be really useful at times, it's where I found this article, titled Javascript You Need To Know For React.
Shorthand property names
const id = 2
const name = 'Bhanu'
const count = 2
const user = {
id,
blogs: count,
name,
}
I've seen & used this in the wild, just didn't know what it was.
Optional Chaining
Consider the expression
a?.b.
This expression evaluates toa.b
if a is notnull
and notundefined
, otherwise, it evaluates toundefined
You can even chain this multiple times likea?.b?.c
Nullish Coalescing Operator
Consider the expression
a ?? b
. This evaluates tob
ifa
isnull
orundefined
, otherwise, it evaluates toa
Another one I've seen & used in the wild, with no idea what it was.
Array.prototype.reduce()
The array reduce method reduces the array of values into a single value. It executes the callback function for each value of the array.
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15
JavaScript Modules and how to effectively work with Export Import
Well written article by Tapas Adhikary. Concise.