Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active September 22, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vielhuber/c0abd5f8b4b99b1c9e4654d83621d29f to your computer and use it in GitHub Desktop.
Save vielhuber/c0abd5f8b4b99b1c9e4654d83621d29f to your computer and use it in GitHub Desktop.
semicolons (with or without syntax) #js
// js has auto semicolon insertion
BEFORE
var x = 1
var y = 2
AFTER
var x = 1;
var y = 2;
BEFORE
x
++
y
AFTER
x++;
y;
BEFORE
function foo() {
return
42
}
AFTER
function foo() {
return;
42;
}
BEFORE
function foo() {
return
42;
}
AFTER
function foo() {
return;
42;
}
}
// if you use code without semicolons and next line begins with (, use ";" before it!
var i = 1
(function() { alert(i); })() // error
var i = 1
;(function() { alert(i); })() // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment