20 Feb 2022

The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document’s viewport.

Syntax to create Intersection Observer API

const observer = new IntersectionObserver(entries => {
console.log(entries)
})
References

MDN Web Docs
webdevsimplified

20 Feb 2022

A pure function is a function which:

Given the same input, always returns the same output and the Produces have no side effects.

Preoperties

  • No random values
  • No current date/time
  • No global state
  • No mutation of parameters

Benefits

  • Self-documenting
  • Easily testable

18 Feb 2022

In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties. There are 7 primitive data types:

  • string
  • number
  • bigint
  • boolean
  • undefined
  • symbol
  • null

All primitives are immutable; that is, they cannot be altered. It is important not to confuse a primitive itself with a variable assigned a primitive value. The variable may be reassigned to a new value, but the existing value can not be changed in the ways that objects, arrays, and functions can be altered.

References

MDN

10 Feb 2022

  1. Shortest Program in JS: Empty file. Still, browsers make global Execution context and global space along with Window object.
  2. Global scope: Anything that is not in a function, is in the global space.
  3. Variables present in a global space can be accessed by a “window” object. (like window.a)
  4. In global scope, (this === window) object. For example refer the below,
var a = 10;

Console.log(windows.a) // 10
Console.log(a)  // 10
Console.log(this.a) // 10

2 Feb 2022

An important difference between function declarations and class declarations is that while functions can be called in code that appears before they are defined, classes must be defined before they can be constructed.

class hoisting

Classes defined using a class declaration are hoisted, which means that JavaScript has a reference to the class. However the class is not initialized by default, so any code that uses it before the line in which it is initialized is executed will throw a ReferenceError.

const p = new Rectangle(); // ReferenceError
class Rectangle {}

This occurs because while the class is hoisted its values are not initialized.

Function and class expression hoisting

Function expressions and class expressions are not hoisted.

References

w3schools

5 Jan 2022

The state of an application (or anything else, really) is its condition or quality of being at a given moment in time—its state of being. Whether something is stateful or stateless depends on how long the state of interaction with it is being recorded and how that information needs to be stored.

Stateless

A stateless process or applicaton can be understood in isolation. There is no stored information or references to past transactions. Each transaction is made as if from scratch for the first time. Think of stateless transactions as a vending machine: a single request and a response.

Stateful

Stateful applications and processes, however, are those that can be returned to again and again, like online banking or email. They’re performed with the context of previous transactions and the current transaction may be affected by what happened during previous transactions. For these reasons, stateful apps use the same servers each time they process a request from a user.

References

Redhat blog