JavaScript Execution Context

Abel Gechure
1 min readJun 3, 2021

When a function in JavaScript is called it is provided an execution context. The execution context is a JavaScript Object that is either implicitly or explicitly passed at the time of the function’s call. To Explicitly pass the execution context to a function you use the methods call, apply and bind

What is the keyword this ?

this returns the current execution context while the function is being run.

An example of an implicitly set context

let user= {
name: 'bob',
age: 20,
occupation: 'software developer'
profile: function(){
console.log(`${this.name} is ${this.age} years old and he is a ${this.occupation}`
}}
user.profile()
//=> LOG: bob is 20 years old and he is a software developer

in the above example, this was set to user object. A simple way to think of it when the context is set implicitly like in the example above is when you call exampleObject.exampleFunction(), the context inside of exampleFunction will be the object it has been called on which is to the left of the (.): exampleObject.

An Important place where this is implicitly set is when new instances of classes are created

for more on this here is a link

--

--