Last active
May 14, 2019 14:47
-
-
Save alexkhismatulin/8c13b9cd6813e1883e4f5e13f698dc4f to your computer and use it in GitHub Desktop.
The case when you do need a semicolon in JavaScript. Check it out in StackBlitz demo: https://stackblitz.com/edit/when-you-need-a-semicolon
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
const items = [1, 2, 3] | |
try { | |
// you need a semicolon after following line to make it work | |
items.shift() | |
(items.length && items[0] === 2) && items.unshift(1) | |
} catch(e) { | |
console.error(e) | |
} | |
/* | |
Parser will try to call the code inside the try block this way: | |
items.shift()(items.length && items[0] === 2) && items.unshift() | |
Output: Error: items.shift(...) is not a function | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment