javascript - Using the -- operator in a while loop produces unexpected results -


in formula,

var x = 5; while(x--) { console.log(x) } 

the output is

4 3 2 1 0 

why 0 output? on fifth iteration, x-- equal 0 falsey, loop should not run.

on same token, returns true

var x = 1; (x--) == true; 

but returns false

0 == true 

x-- evaluates first , decrements variable. if use --x instead, expect.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -