frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

99 - Closure 2 - javascript

Open jsartisan opened this issue 1 year ago • 0 comments

index.js

export function createFunctions() {
  const functions = [];
  
  let i = 0;
  while(i < 10) {
    let j = i;
    let func = function () {
      console.log(j);
    };
    
    functions.push(func);
    i++;
  }

  return functions;
}

jsartisan avatar Jul 01 '24 12:07 jsartisan