Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created November 15, 2022 13:48
Show Gist options
  • Save JoshCheek/fdd692ec9eb183300db92da8f4cf474a to your computer and use it in GitHub Desktop.
Save JoshCheek/fdd692ec9eb183300db92da8f4cf474a to your computer and use it in GitHub Desktop.
Example of putting the semicolon at the beginning of the line in JS
// https://twitter.com/josh_cheek/status/1592514535789060101
console.log(1)
// this line will "continue" the previous one so
// it gets a semicolon to stop it from doing that
// JS would otherwise consider it a function call,
// ie `console.log("hello")(function() { ... })
;(function() {
console.log(2)
})()
// this one, too, it would otherwise be... what I\'d
// call "bracket access", like how you access array
// elements
;[3, 4, 5].forEach(i => console.log(i))
// this one is well behaved, it doesn\'t need a semicolon
Number.prototype.times = function times(fn) {
for(i=0; i < this; ++i) fn(i)
}
// the minus here could be a binary operator, so: semicolon
;3..times(i => console.log(i+6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment