Spread Operators in Javascript
· ☕ 3 min read
A spread operator (...) provides a quick way to expand a Javascript object or array. Array or object is a collection of values. Accessing individual values within the array will require one to use a loop. 1 2 3 4 5 6 7 8 9 10 const fruits = ["orange", "apple"]; for (let i = 0; i < fruits.

Variable Scoping in Javascript
· ☕ 5 min read
Scope of a variable refers to the visibility of that variable. Since the visibility of a variable also determines whether it can be referenced in a valid way, scopes are said to define the ‘life time of a variable’. Scopes in Javascript can be global to the program, or local to the specific block and function.

Operator Precedence in Javascript
· ☕ 2 min read
Operator precedence includes unary, increment, basic arithmetic, logical and assignment operators - roughly in that order. The precedence can be remembered by BEUDMASLAS. brackets exponent unary & prefixed increment / decrement division multiplication addition subtraction logical assignment suffixed increment / decrement Not quite exciting as BODMAS or PEDMAS (math, anyone?

Javascript New Keyword
· ☕ 2 min read
New operator is used to initialize objects and create a new instance of the object. You would have seen new used in the object context in an earlier post. The usage is something like the below - 1 2 let worldExists = new Boolean(false); console.log(worldExists); // [Boolean: false] worldExists is an object that has a value of type ‘boolean’.

Rest Parameter in Javascript
· ☕ 1 min read
Rest parameter enables you to signify an ‘infinite’ parameter to a function. ... serves two purposes in Javascript - Spread operator - know what spread operators can do Rest parameter for a function Rest parameter just tells Javscript that there can be zero or infinite parameters for the function.

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?