Category: JavaScript

  • IIFE in JS

    IIFE stands for “Immediately Invoked Function Expression” in JavaScript. It is a design pattern where a function is defined and executed immediately after its creation. This pattern is often used to create a private scope for variables, preventing them from polluting the global scope. Here’s a basic example of an IIFE: In this example, an…

  • Lexical Scoping (or Static Scoping) Vs Dynamic Scoping

    Static (or lexical) scoping and dynamic scoping are two different ways that programming languages determine the scope of a variable. JavaScript uses lexical scoping. Lexical Scoping (Static Scoping): Example in JavaScript: Dynamic Scoping: Example (hypothetical) dynamic scoping behavior: In summary, JavaScript employs lexical scoping, where the scope of a variable is determined by its location…

  • Array.from in Javascript

    The Array.from() method in JavaScript is used to create a new, shallow-copied array from an iterable object or an array-like object. It takes an iterable or array-like object as its first argument and an optional mapping function as its second argument. The mapping function is applied to each element in the iterable or array-like object.…

  • JS: Difference between isNan() and Number.isNan()

    isNaN() and Number.isNaN() are both JavaScript functions, but they behave slightly differently. isNaN() Function: Example Number.isNaN() Method: Example: In summary, while both isNaN() and Number.isNaN() are used to check if a value is NaN, Number.isNaN() is more reliable and is generally recommended for checking NaN values in modern JavaScript code due to its lack of…