Scope Chain Example

JavaScript searches for variables through the scope chain.

Preview

Code

<script>
let globalVar = "Global";

function first(){
  function second(){
    console.log(globalVar);
  }
  second();
}

first();
</script>

More JS Scope Examples (7)