Scope

Friday 25 May 2018

What is a JavaScript Scope

A JavaScript Scope is, put simply, what determines whether or not you can see variables. There are two types of JavaScript scope, Global and Local.

Global Scope

An easy way to differentiate the two scopes is looking at where the variable has been declared. If the variable is declared outside the function it is Global, inside is Local. If a variable is global, all scripts and functions on any web page could access it.

Local Scope

Basically the opposite to a Global funtion as the variable is decleared inside the JavaScript function and can only be accessed within the same function