1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-10 08:44:28 +02:00

[javascript] Add notes about ASI. Closes #424.

This commit is contained in:
Adam Brenecki
2013-11-26 18:28:44 +10:30
parent 1e60055977
commit ec3343839f

View File

@@ -31,8 +31,8 @@ doStuff();
// wherever there's a newline, except in certain cases. // wherever there's a newline, except in certain cases.
doStuff() doStuff()
// So that we don't have to worry about those certain cases (for now), we'll // Because those cases can cause unexpected results, we'll keep on using
// leave them on. // semicolons in this guide.
/////////////////////////////////// ///////////////////////////////////
// 1. Numbers, Strings and Operators // 1. Numbers, Strings and Operators
@@ -218,6 +218,18 @@ function myFunction(thing){
} }
myFunction("foo"); // = "FOO" 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 // JavaScript functions are first class objects, so they can be reassigned to
// different variable names and passed to other functions as arguments - for // different variable names and passed to other functions as arguments - for
// example, when supplying an event handler: // example, when supplying an event handler: