zero = false

August 1st, 2006 . by polyGeek

I 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. :-)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Digg
  • Facebook

Leave a Reply

Name

Mail (never published)

Website

- Why ask? This confirms you are a human user!

   




© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites