Blog Title : Some Javascripts Topic

24-08-2021

Explain Hoisting in javascript? 🤔

Hoisting is a behavior. Where you can define your variable bottom of moving declarations to the top.
In JavaScript, a variable can be declared after it has been used.


What is Closures in JavaScript? 🤔

A closure is a function having access to the parent scope.

Why we need closer ? 🤔

it is make function have private variable.

Explain with example:

let assume, we create a function that will counter after every click on the button. so first I have declared " x = 0 ". and then create a function with the name " add() ". Whenever I clicked the " add button ". that action access " add()" function. In this function, we can increase our counter easily. But x is a global variable that can access by any other function. We want to declare a function that has its own private variable. For that we use closure.JavaScript supports nested functions. In closure, we declare a variable under the outer function and that variable only accesses the inner function. Code Example:


What are callbacks? 🤔

Callback is a function.It is passed as an argument to another function.This technique allows a function to call another function.

A callback function can run after another function has finished.

Example of below code:


What are high order Functions in javascript? 🤔

Higher-order functions are functions that take other function as arguments or return functions as their result.

For example, the map function on arrays is a higher order function. The map function takes a function as an argument. for example.

another example


What are arrow functions? 🤔

Arrow functions were introduced in ES6.
Arrow functions allow us to write shorter function.
Before use arrow function :

After use arrow function:


What is Destructuring? 🤔

The Destructuring is a way to access array and object value in variable
Let me explain with example

In above code, If i want to access rahul then i do using like this list[0].

In Destructuring way, we can access array using "firstname" name variable.
In above code, You can access array using firstname variable and lastname variable.