All about {ES6 & JS}

sushmoy barua
4 min readMay 6, 2021

var vs let:

  1. Scope of a variable declared as var is the function or the global (accessible for all) environment.
  2. Scope of a variable declared as let is the code block( accessible inside a particular block )
  3. Variable declared as let are not hoisted(JavaScript’s default behavior of moving all declarations to the top of the current scope)

Block Level Declaration: Any valid statement confined within curly braces( {} ) can be defined as a block. In ES6 let is declared inside a block and will be accessible within the block. Which ensures the security and privacy of data.

On the other hand, var can be accessible globally ( out of the block)

Block binding in loops: Let’s know binding first

Binding: Variable is more formally called binding. When we declare and/or initialize a variable, we actually bind a value to a name inside a scope. Scope usually refers to a specific part of a program.

Then what is a loop?

Loop: Well loop is a way of performing repetitive tasks.

There is basically 5 types of loops in Javascript, which remained almost the same in the newly ES6 version. Those are:

  • For loop
  • For…in loop
  • For…each loop
  • For of loop
  • While loop
  • Do…while loop()

So these two (loops, variables) declared in a block can be called block binding

Functions with default parameter values: What is a function?

A function is a block of code designed for a particular task

Normally functions can contain one or multiple parameters and even no parameter.

Now take a look at this function, here 2 parameters are accepted by the function a, b. When the function is called if both parameters are passed it results in the expected output. Now see the second call of the function, just one parameter is passed ( a = 5), and while initializing the function, b=1 value is set. And after the second call, no error thrown!. That’s because the default value of b is initialized while creating the function! so by default, it takes b = 1.

(=, ==, ===) What is this?

  1. Equal(=): In conventional javascript (=) sign is the assignment operator

Just like let a = 5;

  1. Double Equal(==): Double equal is used as a comparison operator

Like if( a==b)? ‘True’ : ‘False’.

Note it [ it doesn’t check data type, only value]

  1. Triple equal(===): New addition of ES6 Triple equals is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar type. Note: it checks value and data type.

typeof(): typeof function use one check what type data we use

console.log(typeof (42));

output: “number”

It is a really useful function in ES6

Arrow function(): Arrow function is a new feature introduced in ES6 which enables writing concise functions in JavaScript. While both regular and arrow functions work in a similar manner, yet there are certain interesting differences between them.

Anonymous Function: An anonymous function is a function without a name. An anonymous function is often not accessible after its initial creation. Anonymous functions can be used as an argument to other functions or as an immediately invoked function execution.

Spread operator: The spread operator allows an iterable to expand in places where 0+ arguments are expected. It is mostly used in the variable array where there is more than 1 value expected. It allows us the privilege to obtain a list of parameters from an array. Syntax of the Spread operator is the same as but it works completely opposite of it.

const inputValue = […value];

Javascript Prototype: By default, the JavaScript engine provides the Object() function and an anonymous object that can be referenced via the Object.prototype.

console.log(Object);

console.log(Object.prototype);

--

--