JavaScript only has function scope; each function has a scope chain directly to the window object.
Variables are searched layer by layer from the inside out until found.
At the same time, not only can you find and use it, but you can even change external variables.
var color = "blue";
function changeColor () {
var anotherColor = "red";
function swapColors() {
var tempColor = anotherColor;
anotherColor = color;
color = tempColor;
}
swapColors();
}
changeColor();
console.log(color); // "red" External variables can not only be accessed but also modified