summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--javascript.html.markdown16
1 files changed, 14 insertions, 2 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown
index b6d4c8b7..348cbff5 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -31,8 +31,8 @@ doStuff();
// wherever there's a newline, except in certain cases.
doStuff()
-// So that we don't have to worry about those certain cases (for now), we'll
-// leave them on.
+// Because those cases can cause unexpected results, we'll keep on using
+// semicolons in this guide.
///////////////////////////////////
// 1. Numbers, Strings and Operators
@@ -218,6 +218,18 @@ function myFunction(thing){
}
myFunction("foo"); // = "FOO"
+// Note that the value to be returned must start on the same line as the
+// 'return' keyword, otherwise you'll always return 'undefined' due to
+// automatic semicolon insertion. Watch out for this when using Allman style.
+function myFunction()
+{
+ return // <- semicolon automatically inserted here
+ {
+ thisIsAn: 'object literal'
+ }
+}
+myFunction(); // = undefined
+
// JavaScript functions are first class objects, so they can be reassigned to
// different variable names and passed to other functions as arguments - for
// example, when supplying an event handler: