7 JavaScript Concepts That Every Web Developer Should Know
7 JavaScript Concepts That Every Web Developer Should Know

7 JavaScript Concepts That Every Web Developer Should Know

scopes

1. Scopes ??

The understanding scope will make your code stand out, reduce errors and help you make powerful design patterns with it

Local and Global

There are two kinds of scope – global scope and local scope

Variables defined inside a function are in local scope while variables defined outside of a function are in the global scope. Each function when invoked creates a new scope.

JavaScript has function scope: Each function creates a new scope.

// Global Scope
function someFunction() {
    // Local Scope #1
    function someOtherFunction() {
        // Local Scope #2
    }
}

// Global Scope
function anotherFunction() {
    // Local Scope #3
}
// Global Scope

Read More on MDN


IIFE

2. IIFE ??

Immediately Invoked Function Expression

IIFE is a function expression that automatically invokes after completion of the definition. The parenthesis () plays important role in IIFE pattern. In JavaScript, parenthesis cannot contain statements; it can only contain an expression.

(function () {
    //write your js code here
})();



Hoisting

3. Hoisting ??

Hoisting is JavaScript's default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).


No alt text provided for this image

4. Closures ??

closure is a combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In JavaScriptclosures are created every time a function is created, at function creation time. To use a closure, define a function inside another function and expose it.

One powerful use of closures is to use the outer function as a factory for creating functions that are somehow related. Using closures as function factories is a great way to keep your JavaScript DRY. Five powerful lines of code allow us to create any number of functions with similar, yet unique purposes


Callbacks

5. Callbacks ??

callback is a function passed into another function as an argument to be executed later

I will call back later!
A callback is a function 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


No alt text provided for this image

6. Promises ??

The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.


No alt text provided for this image

7. Async & Await ??

The word “async” before a function means one simple thing: a function always returns a promise.

The keyword "await" makes JavaScript wait until that promise settles and returns its result.


Thank You

Thanks for reading, If you find it useful, please share it and follow for more articles

Happy.Coding()


Indu Bala

Senior Software Engineer | Expert in ASP.NET/.Net6, Well versed with Java Script/React.JS, SQL Server | Cross-Cultural Team Leadership | Azure(AZ-900) & Azure AI(AI-900) Certified.

3 年

Nice one

Rahul Anand

Full Stack Developer | C# | .NET | SQL | Angular | JavaScript | Azure

3 年

Nicely written. Loved your way of writing it pointwise. Please write a detailed article on OOJS as well and few design patterns if possible.

要查看或添加评论,请登录

Hidayt Rahman的更多文章

  • Object destructuring in JavaScript

    Object destructuring in JavaScript

    Object destructuring is a useful JavaScript feature to extract properties from objects and bind them to variables…

  • 6 Reasons to learn JavaScript

    6 Reasons to learn JavaScript

    1. Used Everywhere By Knowing only JavaScript, you're able to build an entire web application from the backend to the…

  • How to center things with style in CSS

    How to center things with style in CSS

    Text-Align Method The “text-align: center” method is perhaps the most common one you’ll see for centering. It’s used…

  • How do JavaScript closures work?

    How do JavaScript closures work?

    Every function in JavaScript maintains a link to its outer lexical environment. A lexical environment is a map of all…

  • Angular 4 - Helping Guide

    Angular 4 - Helping Guide

    INSTALLATION Additional Things BOOTSTRAP 3 after inside angular-cli.json (inside project root folder) find styles and…

  • A Look Into HTML6 – What Is It and What It Has to Offer?

    A Look Into HTML6 – What Is It and What It Has to Offer?

    HTML6 overview. HTML is a simple web development language that keeps on rolling out new versions, and has started…

社区洞察

其他会员也浏览了