Less code interpretation screw-up's by the JS interpreters.
Example:
if ( a == b)
if ( c == d)
//do something
else
// do something
All legal statements, but were is the else, on the second or first if?
if ( a == b) {
if ( c == d) {
//do something
} else {
// do something
}
}
Now there is no doubt
From: [email protected]
[mailto:[email protected]] On Behalf Of Trevor Orr
Sent: Saturday, February 20, 2010 4:33 PM
To: mootools
Subject: [Moo] use of {
This not a MooTools but just a general JavaScript question.
I was just curious about the usage of the { in if statements.
Given the 2 blocks below:
if (variable == 'value')
doonestatement;
OR
if (variable == 'value') {
doonestatement;
}
Is there any benefit to putting the { around the statement to execute if
there is only one statement to execute? I have seen code both ways, where
there is never a { if there is only one statement and code where there is a
{ no matter how many statements there are to execute after an if statement.
Is it just a matter of personal preference or does it provide a speed
performance or is there other reasons?
__________ Information from ESET Smart Security, version of virus signature
database 4883 (20100220) __________
The message was checked by ESET Smart Security.
http://www.eset.com