It’s time for another post, this time ES2019 features. Here are all the features and examples:
Array#{flat,flatMap}
[1, 2, 3].flatMap((x) => [x, x * 2]);
// => [1, 2, 2, 4, 3, 6]
[1, [2, [3]]].flat(Infinity);
// => [1, 2, 3]
## Object.fromEntries
javascript
const iterableOfEntries = new Map([
['cat', 'dog'],
['life', 42]
]);
const obj = Object.fromEntries(iterableOfEntries);
console.log(obj); // { cat: "dog", life: 42 }
## String#{trimStart,trimEnd}
javascript
" Hey JS!".trimStart(); // "Hey JS!"
"Hey JS! ".trimEnd(); // "Hey JS!"
## Symbol#description
javascript
const symbol = Symbol('TC39');
console.log(symbol.description); // 'TC39'
console.log(symbol.hasOwnProperty('description')); // false
## Optional Catch Binding
javascript
try {
throw new Error("End of life!");
} catch { // ✋ no params for catch
console.log("^ you are dead anyway!");
}
## JSON ⊂ ECMAScript
javascript
// Without the proposal:
"foo<U+2028>bar<U+2029>baz" // → SyntaxError
// With the proposal:
"foo<U+2028>bar<U+2029>baz" // does not throw
## Well-formed JSON.stringify
javascript
JSON.stringify('\uD800');
// → '"\\ud800"'
## Function#toString
javascript
function /* this is bar */ bar () {}
bar.toString();
// 'function /* this is bar */ bar () {}'
// ^ previously this was not the case
## Array#sort Stability
javascript
[
{ name: "Jan", age: 20 },
{ name: "Jhon", age: 20 },
{ name: "David", age: 18 },
{ name: "Ram", age: 18 },
{ name: "Sita", age: 18 },
{ name: "Ravan", age: 18 },
{ name: "Asura", age: 12 },
{ name: "Milly", age: 12 },
].sort((m, n) => m.age - n.age);
// People with the same age retain their order.
#javascript#es2019#tc39
About Hemanth HM
Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.