Amazing Things You Should Know About ES6

                 #  Amazing Things You Should Know About ES6
  1. Maps
  2. Arrow Functions
  3. For Of Loop
  4. Set
  5. Getters and Setters

Maps

Maps hold key-value pairs. It’s similar to an array but we can define our own index. And indexes are unique in maps. We using maps set and get as a keyword to set and also to get our index.

var NewMap = new Map();
NewMap.set('name', 'John'); 
NewMap.set('id', 2345796);
NewMap.set('interest', ['js', 'ruby', 'python']);

NewMap.get('name'); // John
NewMap.get('id'); // 2345796
NewMap.get('interest'); // ['js', 'ruby', 'python']

The example above we use set to set the index of the new maps and to get the index we call the keyword of get to get back the index.

Arrow function

An arrow function is also known as a fat arrow function is another type of function but this time you don't need to use the reserve keyword function and curly braces.

// Old Syntax
function oldOne() {
 console.log("Hello World..!");
}
// New Syntax
var newOne = () => {
 console.log("Hello World..!");
}

The new syntax may be confusing a little bit. But I will try to explain the syntax.

There are two parts of the syntax.

  1. var newOne = ()
  2. => {}

The first part is just declaring a variable and assigning the function (i.e) () to it. It just says the variable is actually a function. Then the second part is declaring the body part of the function. The arrow part with the curly braces defines the body part. Another example with parameters.

let NewOneWithParameters = (a, b) => {
 console.log(a+b); // 30
}
NewOneWithParameters(10, 20);