Javascript ES6 complete tutorial

In this tutorial we're going to learn about javascript es6 concepts in depth like const let , symbol, promise , default parameters, object & template literals etc..

🔗Arrow function with this

You can find arow function with this post here

🔗What is symbol ?

A JavaScript Symbol is a primitive datatype just like Number, String, or Boolean.

It represents a unique "hidden" identifier that no other code can accidentally access.

Create a symbol :-

the Symbol() function creates a new unique value each time you call it:

js
let s = Symbol("foo");
console.log(Symbol() === Symbol()); // false

The Symbol() function accepts a description as an optional argument.

The description argument will make your symbol more descriptive.

The following example creates one symbols: firstName

js
let firstName = Symbol("first name");

You can access the symbol’s description property using the toString() method.

js
console.log(firstName.toString()); // Symbol(first name)
access symbol description

Symbols are primitive values, you can use the typeof operator to check primitive type

js
console.log(typeof firstName); // symbol
check primitive type of symbol

If you attempt to create a symbol using the new operator, you will get an error because symbol is a primitive value,

js
let newS = new Symbol();
console.log(newS); // error
Error error while creating symbol using new operator

Symbol usages :-

Eg if different coders want to add a person.id property to a person object belonging to a third - party code, they could mix each others values.

Using Symbol() to create a unique identifiers, solves this problem:

js
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue",
};
let id = Symbol("id");
person[id] = 100123;
console.log(person[id]); // 100123
usage of symbol for creating unique id

🔗Let const

You can find let const in javascript post here

🔗What is promise ?

Is just like a promise in real life what you do is you commit to something by saying I promise to do something for example I promise to make the tutorial post on es6 then that promise either has two results either that promise has completed it is resolved or that promise is failed and it is rejected

What is promise

Similrarly in javascript we have promise , which contain producing code and consuming code

Producing code : is code that can take some time (define resolved and reject in promise)

Consuming code : is code that must wait for the result (result of promise completed or not)

What is promise

Create a Promise :-

To create a promise object, we use the promise() constructor.

js
let promise = new Promise(function (resolve, reject) {
//do something
});

The Promise() constructor takes a function as an argument. The function accepts

two functions resolve() and reject(). If the promise returns successfully, the resolve() function is called.And, if an error occurs, the reject() function is called.

js
let promise = new Promise(function (resolve, reject) {
let x = 0;
if (x == 0) {
resolve("success");
} else {
reject("Failed");
}
});

How to use promise

Promise.then() method takes two arguments, a callback for success and another for failure.

js
promise.then(
function (value) {
console.log(value);
},
function (error) {
console.log(error);
}
);
How to use promise

🔗Spread operator & rest parameter

You can find spread operator and rest parameter post here

🔗Template literals

You can find template literals post here

🔗Object literals

You can find object literals post here

🔗Default parameter

You can find default parameter post here

🔗Classes & Inheritance

You can find Classes & Inheritance post here