Fun Stuff > CLIKC
Need help (lots) with Javascript
snalin:
On the semicolon thing - javascript works without the semicolons. There is one place where it is needed, and that is something like_
--- Code: ---a = b + c
(d+e).print()
--- End code ---
will be parsed as:
--- Code: ---a = b + c(d+e).print()
--- End code ---
So a new line starting with parentheses will be used as method arguments if possible.
Loki:
Huh. The more you know.
Masterpiece:
A semicolon is needed in Java (and probably a lot more programming languages, but I can't be certain) to signal the end of an expression statement. Since every other statement includes at least one expression, most "lines" are ended by a semicolon. If I remember correctly, groups of expressions (curly brackets) and conditions are an exemption to that rule.
--- Code: ---private boolean isMasterpieceMakingSense{ // oh yeah, method declarations also don't end with semicolons, but they're also a group of statements anyway...
if(!isMasterpieceTalkingBonkers && isCodeExampleCorrect){ // start of a group of statements, no semicolon
logging.put("Heck yeah, I made it!"); // semicolon after an expression!
return true; // semicolon after an expression!
}else{ // no semicolon after the first bracket, and none after the else statement
logging.put("Awww, bonkers."); // another expression
return false; // last expression
}
} // end of method declaration, no semicolon.
--- End code ---
Stybar:
Why did you name a method isTalkingBonkers if your returning false when you ARE talking bonkers?
Loki:
More importantly, why is isMasterpieceMakingSense not a function? :-D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version