Skip to main content

New features in JavaScript 2021

 

// Without optional chaining
let userAdmin = undefined;
if (payload.access && payload.access.admin && payload.access.admin[0]) {
userAdmin = payload.access.admin[0].user;
}
// With optional chaining
const userAdmin = payload.access?.admin?[0]?.user;
const arr = ['a', 'b', ['c', 'd']];
const flattened = arr.flat();
console.log(flattened);
// Result: ["a", "b", "c", "d"]

const myArray = [['one', 1], ['two', 2], ['three', 3]];
const obj = Object.fromEntries(myArray);
console.log(obj);
// Result: {one: 1, two: 2, three: 3}

ES2021

String.prototype.replaceAll

// You can break the digits in any way
const BIGNUMBER = 1234_5678_9_0; // 1234567890
// Even after the comma/period
const PI = 3.1415_9265_3589; // 3.141592653589
// However, ending or beginning with an underscore will return an error!const BAD_PI = 3.14_15_; // SyntaxError
const NO_MILLION = _1_000_000; // ReferenceError





Comments

Popular posts from this blog

Online tool to remove background of images

https://www.remove.bg/upload

React way to use D3 - ( Python as API )

The Inspiration Andmap is trying to build new BI product, the tech stacks would be D3 + ReactJS as data visualization frontend, Web API, and Python provides data. As with most new projects, it didn’t take long to figure out the major roadblocks. D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation. In one of our initial discovery sessions, we realized that our application needs to be able to adapt D3 library in ReactJS way. More than that, we prefer utilizing new feature of React - Hooks. Finally, we build  component for each chart and Helpers file for drawing each chart. Here is sample for map chart: index.js: map.js - map chart container - using useEf...