Whenever you're ready, walk me through how you'd approach this.
ValueMomentum builds policy administration software for insurers. A developer wrote the snippet below to build one premium calculator per pricing tier and log each tier's premium on demand. During code review, a teammate ran it and got a result nobody expected.
function buildPremiumCalculators(count, basePremium) {
const calculators = [];
for (var i = 0; i < count; i++) {
calculators.push(function () {
console.log(`Tier ${i}: premium=${basePremium + i * 10}`);
});
}
return calculators;
}
const calcs = buildPremiumCalculators(3, 200);
calcs[0]();
calcs[1]();
calcs[2]();
Tell me the output of this JavaScript code snippet, in order, and explain exactly why each line prints what it does.