Some thoughtsEdit: you should wrap it in this:
;(function () {
'use strict'
// all your code goes here
}())
The ;(function () { }()) bit is known as an IIFE (immediately-invoked function expression). It stops variables from leaking into global scope. This is only a problem in browser JavaScript; in Node.js top-level variables don't leak into global scope.
The 'use strict' directive tells the engine to run the code in strict mode. In a nutshell, strict mode throws more errors, prohibits the dreaded with statement, and throws an error if you try to assign to an undeclared variable. It's useful for finding mistyped variables:
;(function () {
let foo = 42
fooo = 43
console.log('foo is', foo) // foo is 42
}())
;(function () {
'use strict'
let foo = 42
fooo = 43 // Throws an error
console.log('foo is', foo)
}())
You should use strict mode all the time, in development and production, unless you need a 0.01% edge case where part of your file has to be non-strict. If you use Babel it outputs code in strict mode.