When learning JavaScript, the first thing we hear about JS variables is that var is hoisted, whereas let and const are not hoisted.

But is that really true? Technically NO.

Myth #1

Hoisting: JS engine physically places the variables at the top of the code during execution.

As per MDN: Conceptually, for example, a strict definition of hoisting suggests that variable and function declarations are physically moved to the top of your code, but this is not in fact what happens. …


Most of the JS developers out there might have come across one of JavaScript’s most confusing topic: THIS

So, who the hell is this? 🤔

Technically, JavaScript this refers to the object that the function belongs to. And the value of this depends on how the function is called, something known as runtime binding.

In layman’s terms, this points to the owner of the function call, I repeat, the function call, and NOT the function itself. The same function can have different owners in different scenarios.

4 rules decide the value of this

Nothing here. Just the JS this again. :)
Nothing here. Just the JS this again. :)

1. Default binding | Direct invocation

this in Default Binding points to the global object. Default binding is applied for standalone functions and is the fallback option for all other types. …

About

Zeeshan Shamsuddeen

Full Stack Developer | Data Structures Enthusiast

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