So, I am a beginner in JavaScript and I was just playing around by creating some functions! why does if returned there is a different answer and why does if console logged there is a different answer!
SO IF I CONSOLE LOG THIS
const ex = (arra1) => {
for (let i = 0; i < arra1.length; i++) {
console.log(arra1[i]);
}
};
ex([1, 2, 3]);
answer for the above function is 1 2 3
BUT IF RETURN THIS
const ex = (arra1) => {
for (let i = 0; i < arra1.length; i++) {
return arra1[i];
}
};
console.log(ex([1, 2, 3]));
But the answer for this above function is 1