5 important JavaScript Concepts

That Every Developer must be aware off.

Firstly, JavaScript is one of the most fundamental languages in areas of Web-Development ,right now. Across the Internet, there are more than a million websites which are currently running on JavaScript. And we boldly say that it is here to stay. According to the Stack overflow Survey 2019,it was declared to be the #.1 programming language. Now after a brief intro about JavaScript. let us see some of the important concepts of JavaScript. That every developer should know.

1.Scope

    function myFunction() {
    let carName = "Volvo";
    // code here CAN use carName
    }

The Concept of Scope implicates the range or Scope of accessibility and usage of a variable in JavaScript.

In JavaScript naturally, you're always in root scope i.e the window scope. The extension is essentially a box with a boundaries for variables, functions, and objects. These boundaries put limitations on variables and decide if you can access the variable or not. It restricts the visibility or accessibility of a variable to different pieces of the code. You should have an unmistakable comprehension of this idea since it assists you with isolating rationale in your code and furthermore improves on the readability.

A scope can be defined in two ways – Local Scope allows access to everything within the boundaries (inside the box) Global Scope is everything outside the boundaries (outside the box).

2. IIFE (Immediately Invoked Function Expression)

  function logName(userName) {
console.log(`${userName}, you are awesome`);
};

logName("Jane");

As the name suggests IIFE is a function in Java-Script which immediately invoked and executed as soon as it is defined. Variables declared within the IIFE cannot be accessed by the outside world and this way you can avoid the global scope from getting polluted. So the primary reason to use IIFE is to immediately execute the code and obtain data privacy.

3.Closures

const add = (function () {
let counter = 0;
return function () {counter += 1; return counter}
})();

add();
add();
add();

A closure is simply a function inside another function that has access to the outer function variable. Now, this definition sound pretty much straightforward but the real magic is created with the scope. The inner function (closure) can access the variable defined in its scope (variables defined between its curly brackets), in the scope of its parent function, and the global variables. Now here you need to remember that the outer function can not have access to the inner function variable .

4. Callbacks

A callback is simply a function that is passed to another function as a parameter and is invoked or executed inside the other function. Here a function needs to wait for another function to execute or return a value and this makes the chain of the functionalities

5. Async & Await

Stop and wait until something is resolved. Async & await just syntactic sugar on top of Promises and like promises it also provides a way to maintain asynchronous operation more synchronously. So in javascript asynchronous operations can be handled in various versions…

ES5 -> Callback

ES6 -> Promise

ES7 -> async & await