Javascript
GroupBy in Array using Reduce in Javascript
· ☕ 2 min read
There is a really cool way to do group by in an array using reduce. The problem statement - you have an array of objects and need to create different arrays based on similar attributes. This is very similar to the SQL group by statement. Consider the example array -

Manage Client Side Secrets in Javascript
· ☕ 2 min read
How do you maintain secrets on the client-side? In one sentence - there are no secrets client-side. If you don’t want anyone to know about the secret, you should not send it to the client. The need for secrets Client may need user ids/passwords, API keys, API secrets etc. None of them can be trusted to the client.

Convert Strings to Numbers in Javascript
· ☕ 2 min read
There are multiple ways to convert a given string to a number - so, which one to use and where? You would have also seen the more generic post on how to cast value from one type to another. But it may not be so apparent on which option to pick when you need to get numbers from a given string.

Default Function Arguments in Javascript
· ☕ 1 min read
You can easily introduce default values for the arguments passed to a function. Consider this function - 1 2 3 function sayHello(name) { return `hello ${name}`; } Calling this function without arguments will provide a not-so-pretty string. 1 console.log(sayHello()); // hello undefined Even if someone had an existential crisis, I doubt they will like to be called ‘undefined’.

Convert String to Title Case in Javascript
· ☕ 1 min read
We have a string.toLowerCase() and string.toUpperCase() in Javascript, but no out of the box function to convert to title case. Fear not if you are in that pickle - it is quite easy. 1 2 3 4 5 6 7 8 9 function ConvertTitleCase(str) { const strArr = str.toLowerCase().split(" "); for (let i = 0; i < strArr.

Universal Apps and MeteorJS in 2019
· ☕ 4 min read
I was a MeteorJS fan. MeteorJS was an excellent tool to quickly create universal apps. I was not quite a professional developer back in the day (circa 2016-17) but I could recognize the power of Meteor in developing complex web applications that could potentially deployed for multiple devices. There was a time when I was flabbergasted as I, rather alarmingly, saw people moving from Meteor to different platforms.

For Loop Performance in Javascript
· ☕ 3 min read
There are many types of for loops for an array - which should you use? How will you balance performance vs. code readability? Is that even a valid question? Let’s see a few cases. We will be seeing these distinct for loops today - for for-in forEach Note that the performance can be safely ignored for one off loops that do not hold up the user.

Spin-up a quick web server in Javascript
· ☕ 2 min read
Use these two quick ways to get a webserver up and running from any folder. 1. Use http-server Install http-server. 1 npm install http-server -g Navigate to any folder where you need a quick web server and start server. 1 2 cd client/dist http-server You can even proxy requests to a back-end server where required.

Date Object in Javascript
· ☕ 2 min read
Let’s see a few points about when to use a date object, and why use this object vs. a date library? The simplest and quickest way to get date in Javascript - 1 console.log(Date.now()); // 1549025852124 Date.now() does not create an object, and is really fast. But, it is also useless if you want to do anything with the date.

Arguments Object in Javascript
· ☕ 2 min read
Arguments object enables you to treat function arguments with respect.. and the developers with compassion. How do you pass arguments to a function? In its most primitive form: 1 2 3 function getSum(a, b) { return a + b; } This is perfectly ok in an ideal world where Buddha walks the earth.

Non-enumerable Properties in Javascript
· ☕ 2 min read
When you define a prototype for an object you run the risk of counting that as an object property. Use non-enumerable to avoid doing that. Consider this - 1 2 3 4 5 6 7 8 9 Object.prototype.colors = () => { return; }; let fruits = ["apple", "orange"]; console.

Create your Own Javascript Playground
· ☕ 2 min read
I write quite a bit of Javascript on a day to day basis. But, I have a poor memory and keep forgetting things. Things like how I should be using a certain function the right way. This is where web applications like https://jscomplete.com/playground help. But it is not a pleasant experience to have blocks of incomplete code lying around in jscomplete, and keep executing few other parts of the program.

Context of This in Javascript
· ☕ 3 min read
I have often seen how people talk and write about this being all complex and such. But frankly, I don’t understand the pain. All it takes for me to understand is 4-5 iterations of using this in a different functions, classes, modules and so forth, messing up a bit - each time, and trying to do that over & over until I get the right context with the right this.