I'm trying to understand scope in Javscript, and have some problem. Code:
const callback = (arg) => {
console.log(arg);
};
function mainFunc(z) {
const cb = z;
insideFunc();
}
function insideFunc() {
cb('1');
}
mainFunc(callback);
Why insideFunc cannot find cb variable?
cb('1');
^
ReferenceError: cb is not defined
at insideFunc (file:///usr/src/app/file.js:42:3)
at mainFunc (file:///usr/src/app/file.js:38:3)
at file:///usr/src/app/file.js:46:1