Photo by Charles Deluvio 🇵🇭🇨🇦 on Unsplash

********This image has nothing to do with Prototypes in JavaScript, but I couldn’t resist not using it. Feel free to ignore it.******

JavaScript recognizes the need for inheritance, and some other ‘class’ behaviors even though it’s not an object-oriented language like python and c++ for example. JavaScript attempts at using Object Oriented style programming through a property of objects in JavaScript called prototype(denoted as [[Prototype]] in the specification). For beginners like me, prototypes in JavaScript can be difficult to find your way around the first few times you learn about them. After reading quite a bit on them, I realized…

Let’s go over some maybe confusing concepts in the book.

First, at the top of every normal [[Prototype]] chain is the built in Object.prototype object. Also, all normal(built-in, not host-specific) objects in JS descend from the Object.prototype object.

Consider this code: = "bar"

Let’s go over the scenarios that are a bit confusing when foo is not already on myObject directly, but is at a higher level of myObject ‘s [[Prototype]] chain.
Before we get into that, let’s remind ourselves what a data accessor is(was explained in chapter 3)
Consider this code:
var myObject = { a:2 };
The property…


I got confused with why myObject["[object Object]"]results in baz . If you console.log( myObject ); you will find that the 3rd property and value is [object Object]: "baz" . So the string form of myObject is "[object Object]" .

Getters and Setters


Let’s look at the object literal syntax of myObject , it is very similar to
var myObject = { a: function(){ return this.a * 2; }} where to call the value of a we could say myObject.a() . On the other hand, when using getters we can call a by executing myObject.a , without…

Nothing but Rules
Rule #1:- Default Binding

Default binding is the rule that applies when the other 3 rules don’t.
Consider the following code:-

Note that whenever a variable is declared in the global scope, it is the same with a global object, i.e window , property of the same name. There is a slight caveat I noticed while trying the code in different environments. First, if you tried the code in atom, the result is undefined and not 2 , even console.log( global.a ); results in undefined . Also, when you run the code with node, its the…

Let’s look at why we need this in JavaScript.
Consider this code:-

Understanding how this snippet works is not necessary right now. Do understand that in this code snippet, we are able to use the identify and speak function multiple times on the object me and you . Note that we only needed one version of the identify and speak functions rather than having different versions of our function to be used on the object. This code snippet should help understand:-

What is important in this code is to note that we have different versions of identify as opposed to having just one.

That’s really it for this chapter. Chapter 2 is loaded though, so watch out :)

Questions are definitely appreciated =)

Take a look at this code:-

This is a module in JavaScript. For there to be an occurrence of a module, or for a module to be created, the function CoolModule has to be called. When CoolModule is called, the inner scope is created ( remember scope is a set of rules on how identifiers can be accessed ) and closures can occur. Closures here is being observed by executing foo.doSomething(); and foo.doAnother(); . …

Closures is when an inner function, on execution, is able to access identifiers of its outer function even when the inner function is outside its declared lexical scope(the scope it was declared in at author time).
We would see closures in action after the example.

The above is not a good example of closures. Why?
Lets understand something first; bar is the inner function and foo is the outer function. bar accesses variable a of foo . Notice that bar is executed in its lexical scope. As bar is executed, it accesses the variable a .

Block scoping is about declaring variables as close as possible to where they would be used.

In the for loop above, variable i is to used in the for loop alone. That is why it is declared in the for loop’s header. The problem is that this is fake block scoping because i is still accessible in the global scope which defeats the purpose of block scoping; to hide information in the block{} .


With the introduction of let in ES6, let creates a real block scope around any {} it is contained in.

Now this…

We would start by understanding what author time means.
To understand what author time means, we can start by understanding what author time is not. Consider this code:

//this is not author time;

//this is author time

The first code example is not author time because the variable a is not authored by you at write time. I.e you did not write the declaration of a, rather it was declared by the JavaScript engine in advance.
The second code example is author time because you declared a while writing the code, i.e author time

We would use this…

The Process of Compiling and Executing a JavaScript :

Compiling code is the process of changing code from human-readable code, example var a = 2, to machine code, example 00000010.

We would focus on understanding the function of the compiler more clearly when it gets to Code Generation. Code generation is the production of executable code i.e machine language.

Consider this snippet of code, var a =2. There are two distinct things involved when you
look at this line of code; the compiler handles the declaration of this program, i.e var a, while the engine handles the assignment, i.e a =2. …


The name is Dami. I blog about anything I find interesting.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store