Global and Block scope question

Greetings, I’m a bit stuck wrapping my head around the concept of scope. One example shows the following const multiplier as global, but in another example, it shows it as block scope.

*in this example i see 3 global variables, input, controlVal and multiplier. What about number and phase parameter? are they global in scope also?

*in this example it shows number, phase and const val as block. What happens if one does not declare with const or let inside the block? What scope is that?

const input = 8;
const controlVal = input / 2 + 3;

const multiplier = (number, phase) => {
const val = number * controlVal + phase;
console.log(val);
};

Undeclared variables in a block belong to the outer scope, as in function scope if they are inside a function. Undeclared variables in a function belong to the outer scope, as in global. JS declares them in global scope with the var declaration.

1 Like