Reputation: 49
const count = () => {
for (let i = 1; i <= 5; i++) {
if ((2 + 2) == 4) {
return (' Bla ')
}
}
};
console.log(count());
The output: 'Bla' And I was expecting: 'Bla' 'Bla' 'Bla' 'Bla' 'Bla'.
Upvotes: 1
Views: 47
Reputation: 311798
In the first iteration, the function return
s, so the loop does not continue. You could instead call console.log
from within the loop directly:
const count = () => {
for (let i = 1; i <= 5; i++) {
if ((2 + 2) == 4) {
console.log(' Bla ')
}
}
};
count();
Upvotes: 1