mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-19 13:32:10 +02:00
[javascript] Add notes about ASI. Closes #424.
This commit is contained in:
parent
1e60055977
commit
ec3343839f
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user