Javascript Quiz: Scope

Hello coders,
I’m taking Scope Quiz in javascript.
The question is:
How many global variables are in the following program?
const input = 8;
const controlVal = input / 2 + 3;

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

I answered 2 input & controlVal. But multiplier is. variable too? According to me that’s a function right? Can someone explain it to me? Thanks!

Hello @tera5966503337, welcome to the community! Technically, multiplier is a variable, and the object you’re assigning to it is a function. In JS, all types of objects can be assigned to variables, and, since a function is an object, that can too. For example, if you use let instead of const to initialise your variable multiplier, you can then assign something else it:

let someFunc = () => {
 console.log("hi");
}
someFunc();
someFunc = "something else";
console.log(someFunc)
/*output: something else*/

The reason methods declared with arrow syntax are usually int done is because it can be very dangerous to the program if you override methods with something else.

I hope that helps!

1 Like