Skip to content

Instantly share code, notes, and snippets.

@alexkhismatulin
Last active May 14, 2019 14:47
Show Gist options
  • Save alexkhismatulin/8c13b9cd6813e1883e4f5e13f698dc4f to your computer and use it in GitHub Desktop.
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
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