Misunderstanding variable scope in JavaScript
In this post, we are going to understand variable scope and difference between var, let and const keywords in javascript. Variable scope is tricky concept for new developers., especially in javascript. Most of beginner developers make common mistake like defining the variable inside the function and expecting it to access outside the function. Understanding var,…
Using index as a key in React (anti-pattern)
What are lists in React ? Lists are used to display data which are similar in ordered format . Often they have same type i.e an array of similar kind of data rendered into a list tag using some version of for loop. How does react render lists? DOM Before we learn how react renders lists…
Object references and copying
One of the fundamental differences of objects versus primitives is that objects are stored and copied “by reference”, whereas primitive values: strings, numbers, booleans, etc – are always copied “as a whole value”. That’s easy to understand if we look a bit under the hood of what happens when we copy a value. Let’s start…
Introducing constructors
If we need to create multiple object of same shape then one of the way to define the shape of is by using the function. we have to create an empty object, initialize it, and return it. A better way is to use a constructor. A constructor is just a function called using the new keyword. When…
Scheduling: setTimeout and setInterval
We may decide to execute a function not right now, but at a certain time later. That’s called “scheduling a call”. There are two methods for it: These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers…
Utility Types in TypeScript
What are utility Types? In TypeScript, utility types are built-in types that allow you to manipulate and transform existing types. They can be used to extract, exclude, or modify the properties of an existing type, or to create a new type based on an existing one. TypeScript provides several utility types to facilitate common type…
Using defer inside a loop
The defer keyword allows a function call to be postponed until the surrounding function has completed execution. This can be useful for reducing redundancy in code, such as when a resource needs to be closed after use. However, it’s important to be mindful of using defer within a loop, as it can have unintended consequences…
Thinking concurrency is always faster
Many developers mistakenly believe that a concurrent solution will always be faster than a sequential one, but this is not always the case. The performance of a solution depends on various factors, such as the efficiency of the concurrency structure, the parts that can be processed in parallel, and the level of contention among the…