learn
Object Assign Method in Javascript
· ☕ 1 min read
assign method of an object allows us to merge two objects quickly. 1 2 3 4 5 const name = { name: "earth" }; const position = { position: 3 }; const planets = Object.assign(name, position); console.log("planets: ", planets); // { name: 'earth', position: 3 } You can also use Object.

Property Descriptors in Javascript
· ☕ 2 min read
Property descriptors define property behaviour. They are attributes of the property. Everything is an object in Javascript. Yes, I know - except those pesky things called primitives on which objects are built. We saw some (quick discussions on objects and properties)[/objects-and-props-in-javascript/] before - but I wanted to outline the descriptors further.

Currying in Javascript
· ☕ 2 min read
Currying is a technique of splitting functions with one or more arguments into a sequence of functions that are invokable with predefined arguments. In other words, you can split fn (a,b,c) into fn(a)(b)(c). That was not quite helpful - let us see an example. 1 2 3 4 5 6 let getSquared = (x, y) => { return x * y; }; let getSquared = getProduct.

Comma operator in Javascript
· ☕ 2 min read
Did you know how to use comma operator in Javascript? A simple , can separate expressions in the same statement, evaluate left-to-right in the expression, pick the right most valid value as the result, and confuse other developers - all within the blink of an eye. We have discussed about operators when discussing operator precedence.

Javascript `typeof` issues and what to do about them
· ☕ 2 min read
typeof is useful but has inherent issues. There are gaps between what a developer expects in terms of consistency and what typeof delivers. Let us look at a few examples - 1 2 const i = 1; console.log(typeof i); // number typeof is a unary operator, and does not require brackets.

Array `copyWithin` - what's the point?
· ☕ 2 min read
You must have seen the copyWithin() method for an array, and surely wondered what it can do. copywithin copies elements from one position to another position in the same array. (Just kidding about the wondering thing - no one ‘wonders’ today, they just Google). 1 2 3 4 const fruits = ["apple", "orange", "grapes", "banana"]; fruits.

Find Difference Between Arrays in Javascript
· ☕ 1 min read
Use set and filter to find the difference between two arrays. 1 2 3 4 let fruits1 = ["apple", "orange", "grapes"]; let fruits2 = ["banana", "mango", "apple"]; let difFruits = [...new Set(fruits1)].filter((item) => !fruits2.includes(item)); console.log(difFruits); // [ 'orange', 'grapes' ] Similarly if you want to find the elements common in both arrays, you could employ a slightly different strategy.

Initiate Arrays with Data in Javascript
· ☕ 1 min read
Create arrays and initiate data in a single statement. Traditionally you would do the below to initiate the array and fill it with values - 1 let planets = ["mercury", "venus", "earth"]; This is a-ok if you know the values, but what if you want array to have fixed elements with pre-defaulted values?

Empty and reset objects in Javascript
· ☕ 2 min read
Is emptying objects akin to destroying them? Is destroying of objects easier than creating them? Let’s find out. Initiate an object. 1 2 let apple = { name: "apple", color: "red" }; console.log("apple: ", apple); // { name: 'apple', color: 'red' } Reset value 1 2 3 // the easy way to reset apple apple = {}; console.

Sleep Function in Javascript
· ☕ 1 min read
Sleep holds off your function execution for specified time. This is super useful whenever you want to hold off something for ‘x’ time. Here are two ways in which you can get your program to sleep for a while. setTimeOut 1 2 3 4 5 6 7 8 9 10 11 12 13 function sleep() { console.

Template Literals in Javascript
· ☕ 1 min read
Template literals provide an easily readable way to embed expressions within string literals. For example - 1 2 3 const thirdSmartPlanet = "earth"; const fact = `${thirdSmartPlanet}is flat`; console.log("fact: ", fact); // fact: earth is flat Earlier, you had to combine strings and variable like so -

Destructuring Variable Assignments in Javascript
· ☕ 3 min read
Destructuring assignment feature provides an easy, readable way to handle object and array assignments. ES6 introduced assignment destructuring, which provides a clean and more readable way to assign variables. The old way - 1 2 3 4 const fruits = { apple: { color: "red" }, orange: { color: "orange" } }; const appleTheFruit = fruits["apple"]; console.

Arrow Functions and `this` in Javascript
· ☕ 3 min read
Arrow functions have made our life much much easier. You can now refer to this without fearing the bogeyman. How did we write functions in the dark ages? Here’s a typical function. 1 2 3 4 5 6 function getSum(i, j) { // or const getSum = function(i,j) { return i + j; } console.