TypeScript decorators are a way to modify or extend the behavior of classes, methods, or properties in a declarative manner. They are denoted by the @ symbol and are applied using a syntax similar to annotations in other languages. Decorators are commonly used in TypeScript with frameworks like Angular, NestJS, and libraries like MobX. They […]

Installation and Jest setup Refer to https://jestjs.io/docs/getting-started Matchers Full list of matchers: https://jestjs.io/docs/expect Matching exact equality with toBe Matching value equality with toEqual Matching opposites with not Matching truthiness, null, undefined and defined Matching numbers Matching floating point numbers Matching strings using regular expression with toMatch Matching arrays and iterables with toContain Matching exceptions with […]

This article will illustrate the inner workings of JavaScript. It will answer questions like: Is JavaScript single-threaded or multi-threaded? If it really was single threaded, does that mean that JavaScript will run slower than code in multi-threaded languages because it could not take advantage of processing code in parallel? What is the difference between a JavaScript engine and a JavaScript runtime environment?

This method allows a precise addition to or modification of a property on an object. By default, properties added using Object.defineProperty() are not writable, not enumerable, and not configurable. Data descriptor vs accessor descriptor A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is […]

Types of tests Unit Tests test very specific, low-level pieces of functionality for example if a function returns the expected value. Integration Tests ensure that the individual pieces of your application work together correctly. For example if a method invocation successfully calls an API which in turn stores a value in the database. Single-service integration […]

This article will demonstrate how to test JavaScript files in NodeJS using the libraries Sinon, Mocha and Chai. Sinon is often installed together with Mocha and Chai, but it is not required.

This article explains how to load JS code asynchronously and when you should defer its execution.

You can use this as a Cheatsheet whenever you do array related operations

Values in a new Set() are unique, they only occur once. You can mySet.add(), mySet.delete(), mySet.clear(). You can check its mySet.size or if it mySet.has(“a”). Avoid that pitfall: If you add objects like in the following example, remember that you create a different object each time: Set values are unique and case sensitive: Convert Array […]

Setup Fakes, spies and stubs are created in the default sandbox which needs to be restored after each test to prevent memory leaks. We use a Mocha hook plugin for that: Types of test doubles Type What it does Behavior Pre-programmed behavior Pre-programmed expectations When to use Fake records arguments, return value, the value of […]

Let’s say you have and want to get rid of item2. How do you do that in JavaScript? Now, newData contains: Or, if you have the key stored as a string in a variable called key: A simple utility function would look like this: Using a list of allowed keys This will make a shallow […]

From latin iterat meaning “repeated” an Iterator provides functionality that allows you to go through (iterate over) each item in a collection of objects.

A Generator is a function that can be paused and resumed at a later time, while having the ability to pass values to and from the function at each pause point.

The basic idea is this: You want to be informed whenever a change (mutation) on a element or its child elements occurs. A change can be a modification of an element’s attributes, its text or if there was a child node appended or removed.

Would you have any clue what an Observable is good for, just from its name? Ok, you can observe something and the ending ‘-able’ might tell you that it lazily waits for you to be observed. Right! But how? By whom? When and why?

Destructuring is a powerful feature in JavaScript and TypeScript that allows you to unpack values from arrays or objects into distinct variables. Destructuring arrays Destructuring objects Destructuring with Function Parameters Destructuring with Rest Operator Destructuring with Default Values Destructuring in Loops Destructuring in Class Constructors Destructuring with Aliases

let x = []; What is the content of x? If you said an empty array you would be wrong, strictly speaking. The right answer is that x contains a reference (e.g. <#525>) which points to a memory location which contains the value []. let x = 5; What is the content of x here? […]