Javascript
Dot Notation Gotchas in Javascript
· ☕ 2 min read
It is quite common to use dot notation to access object’s props. How can you ever go wrong? We have seen a bit of dot and bracket notations in all about Javascript objects and props post. We have learnt to use dot notations to make our code more readable -

Javascript date feature that I could have lived without
· ☕ 2 min read
Be aware of hidden Javascript features that can break your code before you say “ugh..”. Consider the below code that prints today’s date - 1 2 3 const dt = new Date(); console.log("dt: ", dt); // 2019-03-31T13:56:42.552Z All looks good? Let us now create a target date for my payment - it is 1.

Concat vs. Push for Arrays in Javascript
· ☕ 1 min read
Someone once said “there shall be standards, and there were standards”. But no one said anything about consistency, uniformity, and stuff like that? The question is of course not about standards. Let me ask you this one thing - do you have any idea what’s going on with push and contact?

Gotchas of Singleton Classes in Javascript
· ☕ 3 min read
Be careful about using singleton patterns in Javascript classes. It may have unexpected side-effects and can be the most dreaded evil overlord you encounter on that day. Let us take this example of an Account class that is used by all logged-in users. Users set a role and are shown accounts based on the role.

Class Methods and Comma in Javascript
· ☕ 2 min read
Where does a comma fit in the class methods? No where. Where do I remember it from, then - Vue objects. When I started using Vue full time some time in 2017, I had this problem with putting commas everywhere. These were becoming like issues with semicolons - except that VS Code Prettier takes care of my semi-colons.

Newbie Mistakes in Creating Promises in Javascript
· ☕ 5 min read
Promises and promise chaining - really powerful tools to use and make your life as easy as it can be. Until you are stuck in an error that no one seems to have a clue about. Let us see some common errors and how to fix them. 1. Not use error handling in promises It does not demand a lot, people.

Chain Promises in Javascript
· ☕ 3 min read
A chain promises to process data through a promise-laden gold field. A simple promise - 1 2 3 4 5 6 7 8 9 10 11 let promiseToLog = new Promise(function(resolve, reject) { console.log("started"); setTimeout(function() { resolve("promise fulfilled.. after timeout"); }, 300); }); console.log("promise initialized"); promiseToLog.then(function(val) { console.log("resolver", val); }); As you have seen earlier the promise gets initialized and next statement (‘promise initialized’) gets executed without waiting to resolve promise.

Ways to a Promise in Javascript
· ☕ 3 min read
You already know that promises enable us to carry out asynchronous transactions. How do you implement in your own programs? I assume you already know what promises do in Javascript](/promises-javascript) and how event driven programming works :) Javascript promise is an object. So, Promise should be as easy as using an object.

Promises in Javascript
· ☕ 3 min read
Promises enable us to carry out asynchronous transactions. Javascript promise is an object, as we all are. It is a way for the program to initiate “something”, and not wait for the process to complete (='async operations’). Runtime engine calls the call back function once the process completes - thereby completing the loop.

Event Driven Programming
· ☕ 3 min read
Javascript is an event-driven programming language. Logic is triggered by a user or system action, and the flow of action continues to be determined by events along the way. These events can be user-input like clicks, system operations like completion of DB read, completion of file load, etc. Events are handed by the event handlers that are defined by you or the underlying ecosystem.

Delete Array Elements while Iterating Array in Javascript
· ☕ 2 min read
Removing array elements while iterating through the elements in a loop can be tricky for a beginner. Consider this - 1 2 3 4 5 6 const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; for (let i = 0; i < nums.length; i++) { console.

Typeof Cheatsheet in Javascript
· ☕ 1 min read
Here’s a quick reference of various values and their types. For further reference: see what types mean in Javascript and type casting in Javascript. Value Type Description true boolean Boolean 1 number Number “1” string String “abcd” string String Boolean(false) object Boolean object Number(0) object Number object String(“abcd”) object String object [1, 2, 3] object Array object Object() object Plain object {} object Plain object function() {} function Function object Code to cross-check -

Avoid Array Constructors in Javascript
· ☕ 1 min read
Array constructor syntax is confusing to both the system and humans. Avoid it when possible. Consider this.. 1 2 3 const planets = ["mercury", "venus", "earth"]; console.log(planets[0]); // mercury Now, let’s say we do the same using a constructor. 1 2 3 4 const num = new Array(3, 1, 4, 5); console.