Last active
March 1, 2019 15:41
-
-
Save Sharaal/0a86afbd4972433d79fa29b586f72064 to your computer and use it in GitHub Desktop.
Errors because of omitting ;
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
/************************************************** | |
* Immediatly executing anonymous function | |
**************************************************/ | |
// Results in error "TypeError: console.log(...) is not a function" | |
console.log('example') | |
(async () => {})() | |
// With using of ; it works | |
console.log('example'); | |
(async () => {})() | |
/************************************************** | |
* Destructioning | |
**************************************************/ | |
// Results in error "ReferenceError: c is not defined" | |
let a, b | |
const c = [1, 2] | |
[a, b] = c | |
// With using of ; it works | |
let a, b | |
const c = [1, 2]; | |
[a, b] = c |
A good remember to avoid the problems:
just remember to start lines with ; when they start with [ or (
So the both use cases would looks like:
// Immediatly executing anonymous function
console.log('example')
;(async () => {})()
// Destructioning
let a, b
const c = [1, 2]
;[a, b] = c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A detailed article about the automatic semicolon insertion (ASI) feature: http://inimino.org/~inimino/blog/javascript_semicolons