I give conditional test to my while-loop but it doesn't seem working. I think it's because of increment operator. but I couldn't find out why
const nums = [3, 5, 15, 7, 5];
let n, i = 0;
while ((n = nums[i]) < 10, i++ < nums.length) {
console.log(`Number less than 10: ${n}.`);
};
expected [3, 5, 7, 5]
actual result [3, 5, 15, 7, 5]
I don't know why 15 came out.
I want to know why while-loop works like this.
Update:
This problem is from the book 'learning javascript 3rd'
and , comma operator doesn't work like I thought it should.
&&) instead?