In essence, I am trying to declare a variable in the condition-part of a while loop in javascript:
while (var b=a.pop()) { do_sth(b) }
Yet, my browser (firefox) doesn't accept that. Instead I have to go like so:
var b while (b=a.pop()) { do_sth(b) }
which works. Is this behaviour expected?
Yes, it is.
If you want to, you can use a for loop, like this:
for
for (var b; b = a.pop(); ) { //Note the final semicolon do_sth(b); }
1.4m articles
1.4m replys
5 comments
57.0k users