Language

Collections


Avoid the “delete” Keyword in JavaScript

const snowbit = {
  age: 15,
  test: "abc",
}
const { test, ...newSnowbit } = snowbit
console.log(newSnowbit) //  {age: 15}

Let me explain, You should not use delete to remove the property from the object because this mutates the original and that can lead to unpredictable behaviours and becomes difficult to debug.

What are wrapper objects for primitive values?

Each of the primitive types boolean, number, bigint, string and symbol has an associated wrapper class (Boolean, Number, BigInt, String, Symbol). In this blog post, we examine what these classes are good for.

Table of contents:

  1. Wrapper classes for primitive types
  2. Instantiating wrapper classes
    1. Generically wrapping primitive values
    2. Unwrapping primitive values
    3. Primitive values vs. wrapper objects
  3. Function-calling wrapper classes
  4. Further reading

Closure

  • Closures: A closure is a function having access to the parent scope, even after the parent function has closed.
  • Closures: A function bundled together with its lexical environment forms a closure.

Advantages and Disadvantages of Closures

Advantages

  • Closures help in data encapsulation, i.e, with closures, you can store data in a separate scope and share it only where necessary.
  • Modern JavaScript libraries (like React) heavily rely on closures for rendering components on state or prop change.

Disadvantages

  • Closures consume a lot of memory space since the functions need to store the value of the variable in memory, even though the function of the variable itself would not be used multiple times in the code.

Promise

  • JavaScript Promises: then(f,f) vs then(f).catch(f)
  • JavaScript Visualized: Promise Execution

    Long story short, Promises are just objects with some additional functionality to change their internal state.

    The cool thing about Promises is that this can trigger an asynchronous action if a handler is attached by either then or catch. Since the handlers are pushed to the Microtask Queue, you can handle the eventual result in a non-blocking way. This makes it easier to handle errors, chain multiple operations together, and keep your code more readable and maintainable!

Symbol

  • JavaScript Symbols: the Most Misunderstood Feature of the Language?

    let a = "foo"
    
    • The primitive is “foo”, not a.
    • Another very interesting aspect around this, is that primitives in JavaScript are immutable. That means you can’t change the number 2 ever. Instead, you can reassign a variable to have another (immutable) primitive value.
    • Symbols are primitive values and can be assigned to variables.

Events

  • All About JavaScript Events

    • Browser Events These events occur in the browser window rather than the HTML page. Event handlers are bound to the window object, not to the element. E.g., load, error, scroll, resize, etc.
    • HTML Events This is the inverse of the browser event. They are the event that occurs in the element, and the event handlers are bound to the element. E.g., click, mouseover, mouseenter, etc.
  • EventTarget.dispatchEvent()

Date

the__alchemist's comment

Thank god. Javascript is the only language where I... wait for it... roll my own datetimes. Moment's central failure, beyond the surprise mutability, is the conflation of Dates and Times with Datetimes. They are not the same, and this causes so many problems. Python's Arrow library made the same mistake, likely inspired by Moment. I've heard JS devs insist that Dates and Times have no place as standalone constructs outside of a Datetime, but this is incompatible with practical use cases. Rust's Chrono? Outstanding. You can find flaws, but it's generally predictable, and most importantly, has fewer flaws than those in other languages. Python's? Kind of messy, but usable. JS's Date and Moment? Unusable.

My favorite Date v Datetime bug is that Chile changes to DLS at midnight and not 1am. So it’s goes 11:59>1am. Many systems that conflate dates and date times take the existence of midnight as an invariant, which it is not. - dexwiz


Children
  1. 'let' vs 'var': What is the Actual Difference?
  2. A Simple Explanation of JavaScript Variables: const, let, var
  3. A pipe operator for JavaScript: introduction and use cases
  4. Arrow Functions vs Regular Functions in JavaScript – What's the Difference?
  5. ECMAScript
  6. Event Delegation
  7. JavaScript Execution Context – How JS Works Behind The Scenes
  8. Micro Frontend Synergy: Techniques for Effective Communication
  9. Proxy
  10. Reflect
  11. Silly
  12. Tasks, microtasks, queues and schedules
  13. The Difference between Web Sockets Web Workers and Service Workers
  14. This
  15. Understanding Map and Set JavaScript
  16. Use Maps More and Objects Less
  17. When You Should Prefer Map Over Object In JavaScript
  18. Why Would Anyone Need JavaScript Generator Functions