Last active
September 22, 2017 23:11
-
-
Save vielhuber/c0abd5f8b4b99b1c9e4654d83621d29f to your computer and use it in GitHub Desktop.
semicolons (with or without syntax) #js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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