summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
authorAdam Brenecki <adam@brenecki.id.au>2013-11-26 18:28:44 +1030
committerAdam Brenecki <adam@brenecki.id.au>2013-11-26 18:28:44 +1030
commitec3343839fb3b7bc548eb5cab8c716c97753c51b (patch)
tree64f0df2a7242a7b8a6a87785bdc65d68528be266 /javascript.html.markdown
parent1e60055977dd82e6e69de43973e2481d93f78b64 (diff)
[javascript] Add notes about ASI. Closes #424.
Diffstat (limited to 'javascript.html.markdown')
-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: