I have a lambda function (arrow or anonymous function) in JavaScript , which declares a variable, but the problem is that it declares it as a global variable, and I I would like it to be local (only accessible within lambda).
(x=>(
a=2,
console.log(a)
))()
console.log(a)
If I try to put var a = 2
within the function, I throw error. Is it possible to declare it locally? and if so, how to implement it?
The first log
, should give 2
, and the second, should give error, because the variable should not exist globally, but the problem is that it always accesses the declared within the function.