JavaScript

Deep copying in JavaScript using structuredClone

Deep copying in JavaScript using structuredClone

  • August 23, 2022

For as long as anyone can remember, deep copying in JavaScript was not a built-in feature and we had to resort to libraries or workarounds to create a deep copy of a JavaScript value. That has changed now. The platform now offers a built-in function that does deep copying for...

Chrome devtools: Using logpoints for logging messages directly

Chrome devtools: Using logpoints for logging messages directly

  • March 24, 2022

When it comes to debugging JavaScript in Chrome devtools, there are two different camps: the console.log fans and the debugger/breakpoint maximalist. I often switch between the two depending on what problem I am tackling. There is a third option that is kind of in the middle. Logpoints provide us with...

How to prevent npm install for unsupported Node.js versions

How to prevent npm install for unsupported Node.js versions

  • March 17, 2022

npm configurations allow us to do quite a lot of nifty things. One of them is to allow the project to set the Node.js version that needs to be used in order to run the project. This also provides us with the functionality to prevent npm install for unsupported Node.js...

Detecting dark mode preference using JavaScript

Detecting dark mode preference using JavaScript

  • March 2, 2022

As dark themes have become popular across the web and across operating systems, we might want to check the user’s operating system preference when they visit our website. This way, we can initialize our website accordingly after detecting their dark mode preference. We can make use of the prefers-color-scheme media...

JavaScript: Split string and keep the separators

JavaScript: Split string and keep the separators

  • February 1, 2022

String.prototype.split() is a valuable method to split strings based on a delimiter. There often comes a scenario when we want to split a string and keep the separators in the result. The same JavaScript method provides a way to do so. Before we get into that, for people who are...

Printing JavaScript stack traces using console.trace

Printing JavaScript stack traces using console.trace

  • January 26, 2022

The console object in JavaScript has a lot more useful functions than the most frequently used console.log method. Debugging errors and finding execution flow can be a lot easier by making use of the console.trace method. It allows us to print the current stack trace where the method was called....

Overriding nested dependencies in NPM

Overriding nested dependencies in NPM

  • January 18, 2022

Whenever we install a particular package, it is common to come across a problem with a dependency’s dependency. With the release of npm 8.3, an overrides attribute has been added to solve this problem and allow overriding of nested dependencies in NPM. The problem Let us say your project depends...

Flatten Arrays in Vanilla JavaScript with flat() and flatMap()

Flatten Arrays in Vanilla JavaScript with flat() and flatMap()

  • January 5, 2022

ES2019 introduced two methods on the array prototype that would make life so much simpler for developers. These are flat() and flatmap() which help in flattening arrays. Array.prototype.flat() As the name suggests, the flat() method returns a new array with elements of the subarray flattened into it, that is the...