ES2015 introduces Promise API as a replacement for callbacks. There are a few things that you may not know.

Promise and the Event Loop

Consider the following async code.

setTimeout(someFunc, 1000);

setTimeout function waits for one second and then places the function someFunc at the end of the event loop. All other functions in event loop are processed before someFunc is taken up for processing.…

Read More

The ultimate guide to JavaScript class pattern explains how the prototype chain works. It explains how we can chain multiple prototypes together. However, for the sake of simplicity, I left out how a put operation on an object property works. Most misunderstandings in JavaScript arises from the assumption that the put operation works similarly to the get operation. Unfortunately, that is not how it works.…

Read More

Consider an empty object. Print the object using toString method.

const obj = {};
console.log(obj.toString()); // [object Object]

We get the result [object Object] in the console. How does it work? (Interview question). Developers who have a strong background in C++ or C# will blindly attribute it to OOPs. All objects inherit from Object.

JavaScript is to Java what Cartoon is to Car.

Read More