Process one or multiple arguments within a function
· ☕ 2 min read
Let’s say you have to write a function that doubles a given number. You also find out that you may get one number (in which case double that number), or multiple numbers (double all numbers). The first thought that comes to mind is to - use different functions (or) check type of input and process differently Consider the below code -

Shuffle an array in Javascript
· ☕ 1 min read
Write a simple logic to shuffle a given array. Consider this array - 1 const nums = [1, 2, 3, 4, 5, 6]; You can shuffle this array by using the following code - 1 2 3 4 5 6 7 8 9 const nums = [1, 2, 3, 4, 5, 6]; nums.

Round-off numbers in Javascript
· ☕ 1 min read
How do you round-off a number in Javascript? The simple way - 1 2 console.log(Math.round("3.14")); // 3 console.log(Math.round("3.72")); // 4 Then, there are other interesting ways.. Round off to the nearest lower whole number Use Math.floor instead of round. 1 2 console.log(Math.floor("3.14")); // 3 console.log(Math.floor("3.72")); // 3 Round off to the nearest higher whole number Use ceil.

Memoization in Javascript
· ☕ 4 min read
What is memoization and where is it useful? Let us do a quick overview and dig into example code. Memoization is a technique that can be used in long, recursive code to cache results from previous executions and speed up the overall process. Consider a long repetitive operation where there is a good possibility that you will have the same arguments for the computation function more than once.

Global variables in async functions
· ☕ 2 min read
How do global variables impact async functions? Does hoisting have a role to play at all? As many beginners have found out the hard way - yes. 1 2 3 4 5 for (var i = 0; i < 5; i++) { setTimeout(function() { console.log(i); }, 500 * i); } What’s the output you’d expect?

Find max and min numbers in array
· ☕ 1 min read
What is the easiest way to find maximum and minimum of a given set of numbers? Well, that’s easy. 1 2 3 4 console.log(Math.max(1, 3, 5)); console.log(Math.min(1, 3, 5)); // 5 1 How about an array? The first thing that comes to mind.. 1 2 3 4 5 6 7 8 9 const nums = [1, 3, 5]; const max = nums.

eChart Display Issues in Tabs
· ☕ 3 min read
I love Vue / Vuetify and use them quite often in my projects. I had to display charts in a couple of recent projects and my search led to v-charts. I was impressed with what the library could do - v-charts is a Vue wrapper for eCharts, the Baidu-developed chart library The v-charts library makes it really easy to use ECharts.

Access an array in reverse in Javascript
· ☕ 2 min read
Access an array in reverse. Consider the array in the code block below - 1 const nums = [1, 2, 3]; Accessing the array is easy enough. 1 2 3 4 console.log(nums[0]); console.log(nums[1]); console.log(nums[2]); /* 1 2 3 */ But, what if you want to access the array from the last element?

Optional arguments using spread while calling functions
· ☕ 1 min read
How about using the spread operator for handling optional arguments, or for null arguments? Consider this code - 1 2 3 function sum(x, y, z) { return x + y + z; } We can choose to pass ‘z’ or not, but ignoring ‘y’ returns an error.

Console.log function for easier debugging
· ☕ 2 min read
Encapsulate a console.log() in a function and use it anywhere - even within the most complex expressions. The most typical console.log - 1 2 console.log("hello world"); // hello world Change it to - 1 2 3 4 5 6 function logThis(expr) { console.log(expr); return expr; } logThis("hello world"); // hello Why the circus?

True comparison using Object.is()
· ☕ 2 min read
Object.is() provides a true comparison for any object. Start using it today if you have missed out so far..! Consider the code below - 1 2 3 4 5 6 console.log("abc" == "abc"); // true console.log(null == null); // true console.log(1 == 1); // true // break console.log(0 == false); // true console.

Tagged Templates in Javascript
· ☕ 2 min read
Tagged templates allow our beloved template literals to be taken to a whole new level. The typical use of a template literal is below - 1 2 3 4 5 let x = 1; let y = 5; console.log(`x is ${x}, y is ${y}`); // x is 1, y is 5 Template literals allow us to avoid stupid statements like this -

Searching the Void in Javascript
· ☕ 2 min read
What is void and does it have a role in modern Javascript? The unary void operator is rather strange and has quirky use cases. Or, should I say ‘had quirky use cases’. Primarily, void was used to check the true undefined. Consider the below code - 1 2 undefined = 0; console.