Languages

JavaScript - what's the difference between scope and context?

0 points
Asked by:
Dexter
300

I'm not really sure what is the difference between scope and context in JavaScript.

Can someone help me understand?

1 answer
0 points
Answered by:
Dexter
300

Scope

Scope determines the visibility (or accessibility) of variables. It's achieved by the use of functions and curly braces. Variables can be defined either in local or global scope.

Here are some runnable examples:

Context

Context is related to objects and how a function is invoked. It refers to the object to which a function belongs when you use this keyword.

 

Summary:

  • scope is function-based while context is object-based,
  • every function call has both a scope and a context associated with it,
  • context is associated with this keyword - a reference to the object to which the currently executing code belongs.
0 comments Add comment
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

â€ïžđŸ’» 🙂

Join