Imagine:
const arr = ['a','b','c'];
let num;
const incr = arr.map((el, i) => {
num += el;
}
// num is undefined in incr
How to get num
inside incr
function so it can increment itself on each loop?
Trying to put num
inside incr
will not result in proper increments as it will be overwritten on each loop.
Shall I use var
instead?