'Is there a way to use a variable inside an arrow function but initialize it inside another function where the arrow function is also called? [duplicate]
I'm trying to access the variable c that is initialized inside myFunc when I call sum.
let sum = (a,b) => {
let result = a + b + c;
return result;
}
function myFunc(){
let c = 5;
return sum(1,2);
}
console.log(myFunc());
But I'm getting an error because of the c that I use inside the arrow function. Don't know if I'm explaining right but I think you get the point by seeing the code above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
