Two Important Rules of ES6 Modules

There are two important Rules, which you need to understand if you’re working with ES6 Modules: Modules are always in Strict Mode (no need to define "use strict"). Modules don’t have a shared, global Scope. Instead each Module has its own Scope.

December 26, 2022 · 1 min · Daman Arora

Destructuring an Array or an Object in ES6

Destructuring is a cool new feature which allows you to easily extract values from an object or an array. It is important to note, that destructuring for arrays is position based, whereas in case of the objects it is based on the names of the keys. Array: let numbers = [1, 2, 3, 4, 5]; let [a, b] = numbers;// a => 1, b => 2 Object: let person = { name: 'Max', age: 27 }; let {name, age} = person; // Notice the {} instead of [] More information may be found here....

December 25, 2022 · 1 min · Daman Arora

Rest and Spread Operators in ES6

ES6 added two important new operators: Rest and Spread. Technically they look the same ( ... => three dots) but they are used in different places. Rest: function sumUp(start, ...toAdd) {} Transforms a list of arguments (1, 2, 3) into an array ([1, 2, 3]) which may be used inside the function. This behavior is triggered when used inside of a function argument list. Spread: let ids = [1, 2, 3, 4, 5, 6]; console....

December 25, 2022 · 1 min · Daman Arora

Arrow Functions and Default Arguments in ES6

In ES6 there were two major additions regarding functions: (Fat) Arrow Functions( () => {} ) and default arguments( doSmth(arg = 1) ). Fat Arrow Functions allow you to use a shorter syntax to create functions: const fn = (arg1, arg2) => return arg1 + arg2 You may leave out the parenthesis around the arguments if only one argument is passed. If no argument is passed, empty parentheses are required. The function body may be written inline and without curly braces if you’re only writing a return statement (return then also may be left out)....

December 25, 2022 · 1 min · Daman Arora

let and const keywords in ES6

let and const are new keywords introduced in ES6 which enable us to change the way we work with variables and constants. Let and const are both block scoped. Prior to ES6, we had only function scope and global scope. Block scope restricts variable access to blocks, i.e. constructs with curly braces, such as if...else, for loops, etc. As an example: In the past, we would declare variables using var as follows:...

December 25, 2022 · 2 min · Daman Arora