The Scope of Variables in JavaScript

  node.js, question

When writing JavaScript or Node.js

let a = 1
 
 // func is a higher-order function
 func(() => {
 Log (a)//sometimes a can access and sometimes a cannot
 })

funcIt is only a generation of higher-order function, which may be shaped likesetTimeoutThe function of, may befs.readFileSuch functions, please do not care about func function implementation.

This issue focuses on a variable A in the callback function, which can access External variable in some higher-order function and not in others higher-order function.

Why is this?

let a = 1;
 let func = () => {
 console.log(a);
 };

Is the grammar wrong ~