EN
JavaScript - what's the difference between scope and context?
1
answers
0
points
I'm not really sure what is the difference between scope and context in JavaScript.
Can someone help me understand?
1 answer
0
points
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