Thursday, August 19, 2010

There is an Order to Things, and you Missed it

When evaluating a condition in JavaScript, the conditions work from left to right, so the following bit of code is completely worthless.

if (someobj.someproperty && someobj) {

The && condition will only proceed to check the next condition if the condition directly before it returned true. In this case 'someobj' must exist before the property 'someproperty' can be read, therefore the final check to see if 'someobj' exists will only be reached if a property of that object exist - at this point it is already assumed that 'someobj' exists. I think I just talked myself into a circle there.

Entirely worthless. There, I said it again.

No comments:

Post a Comment