What's the difference between -
andCode:onload = (function() { });
Thanks, keyboard1333Code:onload = function() { };
What's the difference between -
andCode:onload = (function() { });
Thanks, keyboard1333Code:onload = function() { };
Last edited by keyboard; 09-13-2012 at 03:01 AM.
When parentheses are not required, they are always optional (as far as I know). In other words, if you don't need parentheses, you can choose to add them if you wish.
For example:
if (((a==b))) {...
They can sometimes make the code easier to read, or make sure that a statement isn't ambiguous. For example:
if (a==b||c==d&&e==f) {...
In that case, the code is valid, but it's unclear exactly how the logic works out. So adding some parentheses can help.
Of course there are other cases where they're strictly required, such as when you're calling a function and adding arguments.
In short, unless I'm missing something, those two are exactly equivalent.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
I tend to add parentheses, when it is something that I want to make clearer for readability, ie, in if statements:
PHP Code:if($i == ($j / ($z + ($a - 5))){
}
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
Anime Views Forums
Bernie
Bookmarks