DEV Community


Discussion on: What does "if(variable++)" do in Javascript

lallenfrancisl profile image
Allen Francis

Oh sorry I read the -- one as error thrown. Well regarding what they do, in this particular case with num = 0 initially, the condition never becomes true and the code inside the if statement never executes. Why ? Because its post-increment and post-decrement, which means the value is only incremented in the next line of code after increment is used. Which means inside the condition check num will be still 0 and after the condition check num will become 1 or -1 respectively.