JavaScript - Sample Interview Question (Junior Level)

What will be the output of the following code?

var n = 3;
var someFunctions = [];
for (var i = 0; i < n; i++) {          
    someFunctions[i] = function() {            
        console.log("Number " + i); 
    };
}
for (var j = 0; j < someFunctions.length; j++) {
    someFunctions[j]();                      
}

  1. Number 0
    Number 1
    Number 2
  2. Number 0
    Number 0
    Number 0
  3. Number 2
    Number 2
    Number 2
  4. Number 3
    Number 3
    Number 3
Tests in JavaScript for Juniors

Test Name Difficulty Time (minutes) No. of Questions
JavaScript Online Test for Juniors JavaScript Junior 20 10