zero = false
August 1st, 2006 . by polyGeekI had written the following code:
if(indexNum) { . . .
“indexNum” was a number that corresponded to the clip that the mouse was over. If the mouse wasn’t over a clip then that number would be “null”. So I thought that conditional would work fine because I only wanted to run the code if mouse was over one of the clips.
I could have written: if(indexNum != null) { . . . But I like the conciseness of the former example.
The problem was that sometimes “indexNum” was equal to zero. When that happens the conditional asks: if( 0 ) { . . . Which is always the same as: if( false ) { . . . And that of course is always false.
It took me a while to figure out why my code didn’t work for the first - zero index - clip. So let that be a lesson to you. :-)











