learn
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.

Faster Loops in Javascript
· ☕ 2 min read
We have come to appreciate the performance and readability of the ol’ for loop. But, just how much should we be appreciating the performance? We already did a huge scientific study on different avatars of for. This is the time that we do another highly ineffective test for different types of loops so that we can prove nothing to no one.

Don't Update Function Argument Values
· ☕ 2 min read
Do not change those non-primitive function arguments without understanding the significant implications of your action. Programming languages have pass by reference and pass by value to pass arguments to a function. Javascript passes values for primitives, but references when you are trying to pass objects. Changing arguments within a function will change the arguments for ever.

Problem with Multiplication of Decimal Numbers in Javascript
· ☕ 2 min read
Things are always not how they appear. Especially when it comes to multiplication of decimal numbers in Javascript. Consider - 1 const a = 1.1; Multiply the above number by 3. Compare with expected answer just to make sure you are not seeing a wrong answer. 1 2 3 4 5 6 const a = 1.

Immutability Using Object Seal in Javascript
· ☕ 2 min read
What if you want to allow changing props of an object, but do not want anyone to add new props? Well, that is what Object.seal is for. Objects in Javascript cannot be made immutable by using a const keyword. const works on primitives. It can also make sure you don’t reassign value to an object.

Store your metadata for free in Javascript
· ☕ 2 min read
What if you want to play around with data, but also maintain metadata at the same time? In Javascript you don’t have to create other objects or work hard for that Nirvana that someone in the office was talking about. You just have to go ahead and store the darn metadata along with the object, and everyone is happy.

Equality Checks using NaN in Javascript
· ☕ 2 min read
It is easy to take NaN for granted. But remember - the ‘not a number’ notation is the only powerful object that does not equal itself. First the essentials - you use NaN whenever you do not have variable values in control but want to do a numerical operation on it.

Truly Constant Props in Javascript
· ☕ 2 min read
You can make mere variables and even an object immutable. But, how about a humble object prop? Making object props constant and immutable has practical usage. For e.g. consider this totally practical program to print out fruits and whether they are poisonous. 1 2 3 4 5 6 7 8 const eatable = { poisonous: false, printFruit: function(fruit) { return "name: " + fruit + " | poison: " + this.

Null and Undefined - Heroes who are equal to none in Javascript
· ☕ 1 min read
You have used null. You have used undefined. But, have you ever thought about what they mean to the world and to Javascript? The fact is quite simple - we can’t do a null equality check. 1 2 3 4 console.log(1 == null); // false console.log(0 == null); // false console.

Curry Using Bind in Javascript
· ☕ 1 min read
You can use bind to bind variables of a function, and execute the said function later to get the desired result. You have seen how how closures can be used in Javascript and a bit about currying functions. Here’s one more way of doing that. We can bind available variables for a function and execute function at a later time.