This code below outputs 1
const array = [0, null, undefined, 1, 2, 3];
function countTruthy() {
let count = 0;
for (let each of array) {
if (each) {
count++;
return count;
}
}
}
console.log(countTruthy(array));
//But this block of codes below works according to MOSH’s tutorial on Javascript. I simply want to know how the curly braces affected the code please
whilw this outputs 3
const array = [0, null, undefined, 1, 2, 3];
function countTruthy() {
let count = 0;
for (let each of array) if (each) count++;
return count;
}
console.log(countTruthy(array));