Hey there! Did you also by any chance get this question as part of a coding challenge for a company you applied to? Not such an easy problem, is it?
Today we will see the solution to this medium difficulty problem.
First of all, let’s take a quick look at the code:
Here’s step by step what the code is doing:
What is Object.prototype? Array.prototype? String.prototype? __proto__? Scary stuff!
According to MDN:
Have you ever wondered where do arrays or strings get their native methods from…
In this article I will try to explain what Promises are while keeping it as simple as I can.
Before we dive into asynchronous land, please make sure you fully understand what the call stack is and what single threaded means.
Here are two articles I wrote, please read them and then come back to this one.
Let’s start with a textbook definition:
“A Promise is an object representing the eventual completion or…
To make an analogy, if our program was a food truck, the thread would be the person preparing and serving the food. Each customer would be a line of code and they would have to line up and be served one by one in order.
Now imagine this scene, people coming up to the window, placing an order, being handed their food and leaving. Everything…
The term “stack” comes from the data structure that is used to implement it. A stack, in computer science is a basic structure that holds data and handles it on a LIFO (Last In First Out) basis.
Before looking at closures, please make sure you fully understand what scope is. I’m working on an article about scope and I will share the link here as soon as it’s done.
What exactly are closures?
“A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment).”
Sounds scary at first.
To put it simply, a closure is nothing more than a scope that gets returned by a function together with its return value.
For example, let’s consider a function that returns an object that has two methods.