jsartisan / frontend-challenges

FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
https://frontend-challenges.com
27 stars 4 forks source link

99 - Closure 2 - javascript #103

Open jsartisan opened 3 months ago

jsartisan commented 3 months ago

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;
}