javascript

A collection of 12 post

Using ESLint and Prettier with TypeScript

ESLint's large set of linting rules and the increased commitment to use ESLint by the TypeScript team makes ESLint a great tool for linting TypeScript projects.

Using Google Analytics with Next.js

There are lots of tutorials online that give you instructions on how to set up Google Analytics with Next.js project. But most of them require you to use , a library that basically wraps Google Analytics logic inside a React component. This is good, but I personally prefer a solution that: Does not…

Using Next.js ▲ with styled-components 💅 the easy way

When you need server-side rendering React app. Next.js is the best choice. And when it comes to styling react component first thing comes in my mind is styled-components. Although it depends on your preference. Let say you want to pair Next.js with styled-components. But use styled-components with…

What is a pure function?

What is a pure function? Answer A pure function is a function that satisfies these two conditions: Given the same input, the function returns the same output. The function doesn’t cause side effects outside of the function’s scope (i.e. mutate data outside the function or data supplied to the…

Dependency Injection Container in Node.js

I’m a developer coming from the PHP (PhalconPHP, Magento) ecosystem and my main concern about javascript has been that, apparently, the community has not adopted one of the practices that, for me, has been the most game changing of all: Dependency Injection. What is Dependency Injection Simply put…

What is the purpose of Javascript UI Frameworks?

What is the purpose of JavaScript UI libraries/frameworks like React, Vue, Angular, Hyperapp, etc? Answer The main purpose is to avoid manipulating the DOM directly and keep the state of an application in sync with the UI easily. Additionally, they provide the ability to create components that can…

Why wrapping source file in an immediately invoked function?

What is the reason for wrapping the entire contents of a JavaScript source file in a function that is immediately invoked? Answer This technique is very common in JavaScript libraries. It creates a closure around the entire contents of the file which creates a private namespace and thereby helps…

What is a closure?

What is a closure? Can you give a useful example of one? Answer A closure is a function defined inside another function and has access to its lexical scope even when it is executing outside its lexical scope. The closure has access to variables in three scopes: Variables declared in its own scope…

Event Delegation Explained

What is event delegation and why is it useful? Can you show an example of how to use it? Answer Event delegation is a technique of delegating events to a single common ancestor. Due to event bubbling, events “bubble” up the DOM tree by executing any handlers progressively on each ancestor element up…

res.json() vs res.send() vs res.end() in Express.js

Express is one of the most popular web frameworks for Node.js - probably used by most Node.js developers. It’s an excellent framework that has a myriad of HTTP utility methods, and it also performs well. When working with Express, we get access to a request and a response object, and we can use the…

Pass By Value And Pass By Reference In JavaScript

Until recently, I always think that variables in Javascript are passed by value. BAM! In this post, we will look into pass by value and pass by reference in Javascript. Let’s see what is pass by value and pass by reference before looking into its javascript context. Pass by Value: In Pass by Value…

Map vs forEach in Javascript

Test.