Error Handling & Important topics in ES6

Murad Hossain
3 min readNov 3, 2020

--

Error handling

If there are any errors in code because of mistakes. You can handle those errors by using “try.. catch”. Try is executed if there were no errors occur and catch ignored. If an error occur then catch is executed.

Example:

Var declaration and hoisting

Hoisting is a technique where variables and function declarations using var move top of their scope before execution no matter where they actually declared.

Example:

Block-Level Declarations

Block-level declarations mean that declare variables that can not access outside of the given block scope. Block scopes are created:

1. Inside of a block

2. Inside of function

Let Declaration

Let declarations be the same as var declaration. But you can only access it in the current code block. Since let declarations are not lifted up to the top of the enclosing block.

Block Binding in Loops

variable declare using “var” will be accessible after the loop is completed because the var declaration gets hoisted.

Still, variable “i” can access after the loop is completed because of “var”. declaration.

If you declare variable “i” using “let”. You will be inaccessible after the loop is completed.

Function Scope

When variables are declared inside a function. The variables are only accessible inside the function and inaccessible outside of the function.

Functions with Default Parameter

Default function parameters allow initialized default value as a parameter if no value is passed.

The Spread Operator

Spread Operator(…) used to copy an array, inserting element of one array element to another, can pass as function arguments.

Arrow Function

Arrow functions allow an alternative way to write a function in shorter syntax compared to the traditional function expression.

Destructuring

Destructuring assignment allows us to unpack arrays or objects properties into distinct variables.

--

--