- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Scope
JavaScript Scope & Hoisting
JavaScript Scope
JavaScript scope decides where in your code a variable can be seen and used.
A variable created inside a function belongs to that function.
Code outside cannot see it, which keeps different parts of a program from clashing.
Example
Example
javascript
let outside = "global";
function show() {
let inside = "local";
console.log(outside);
console.log(inside);
}
show();The function can see both variables.
