Using the Builder Pattern in Javascript (With Examples)

In this post, we will learn how to use the builder pattern in Javascript, and see some code examples, as well as advanced concepts like validation and fixed attribute options. If you just want to see the example code, you can view it on Github Basic Usage - Creating a Builder Class The builder pattern is a popular object oriented design pattern that makes it easier to construct object instances....

 · Soham Kamani

How to Set Expiry Time (TTL) for LocalStorage With Javascript

This post will explain how to implement expiry times for items stored in the browsers localStorage. If you’re familiar with the browsers localStorage object, you know that there’s no provision for providing an expiry time. However, we can use Javascript to add a TTL (Time to live) to invalidate items in localStorage after a certain period of time elapses. If you just want to see a working example, you can skip to the last section...

 · Soham Kamani

D3 Geo Projections Explained 🗺

D3 is used extensively for drawing geographic visualizations. D3 uses GeoJSON for representing shapes on maps. This post explains how we can use D3 to convert GeoJSON, that looks like this: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "subunit": "Albania", "su_a3": "ALB", //... //... }, "geometry": { "type": "Polygon", "coordinates": [ [ [20.590247430104906, 41.855404161133606], // ... [20.590247430104906, 41.855404161133606] ] ] } } into a rendered SVG element, that looks like this:...

 · Soham Kamani

Javascript Closures Explained (With Examples)

One of the most important, but often misunderstood concepts in javascript is closures. Understanding closures unlocks programming patterns that would be difficult to use otherwise. In this post, we will understand what closures are, and go through a few examples to solidify our understanding of them. The Lifecycle Of A Function First, let’s take a look at a simple function: function getValue(){ var a = 1 var b = 2 return a + b } var val = getValue() console....

 · Soham Kamani

Using Enums (Enumerations) In Javascript

This post will explain how to implement and use enumerations (or enum types) in Javascript. Enums are types that contain a limited number of fixed values, as opposed to types like Number or String which can have a wide range of values. This is useful for many situations: For example, when describing seasons in temperate climates, you’ll want to limit the options to certain possible values: Summer, Winter, Spring and Autumn....

Last Updated:   · Soham Kamani

How To Sync Your Data Between Google Sheets And Firebase

Google sheets provides an excellent interface for regular users to view and modify data. Wouldn’t it be great if we could use this data to power our Firebase application? Well, as it turns out, we can. In this tutorial, we will be using google scripts, to sync up the data in google sheets and store it in our firebase real time database. Initial Set Up Firstly, set up your database in Firebase :...

 · Soham Kamani

An Introduction to Promises in Javascript

Promises are arguably one of the trickiest concepts to grasp in the javascript world, and even if you know how to use them, it’s difficult to explain how they actually work. This FAQ style tutorial is meant for both beginners and intermediates in the world of promises. If you’re a beginner and have trouble grasping what a promise even is, then go on ahead and start from the first question....

 · Soham Kamani

How Is Javascript Asynchronous And Single Threaded?

Asynchronous programming is one of those programming paradigms that’s extremely difficult to fully understand, until you’ve done enough of it in practice. In an ideal world this shouldn’t be the case, so here’s yet another attempt to explain the concept of async programming, and why its different from parallel programming, in the context of javascript. Everything runs on a different thread except our code. At first glance, this sentence doesn’t seem to make a lot of sense....

 · Soham Kamani