I found some import statements of my .ts files in ionic projects are written as:
import { Component } from '@angular/core'
instead of
import { Component } from '@angular/core';
,which misses a semicolon, and the projects seems run normally, is the import statement need a semicolon at the end actually?
Python does not require semicolons to terminate statements. Semicolons can be used to delimit statements if you wish to put multiple statements on the same line.
All developers writing JavaScript should understand automatic semicolon insertion as it relates to return statements. JS uses automatic semicolon insertion. This means JS engines will execute code and insert any semicolons where it sees fit.
Optional Usage: Semicolons as Statement Separators Other than separating statements on the same line, there is no other obligatory usage of the semicolon in JavaScript.
Semicolons are an essential part of JavaScript code. They are read and used by the compiler to distinguish between separate statements so that statements do not leak into other parts of the code. The good news is that JavaScript includes an automatic semicolon feature.
Javascript only requires semicolons to separate statements in the same line. However I'd recommend you to stick to the good practices and use them.
From the style guide for typescript
Use semicolons:
Reasons: Explicit semicolons helps language formatting tools give consistent results. Missing ASI (automatic semicolon insertion) can trip new devs e.g.
foo() (function(){})
will be a single statement (not two).
I understand that ultimately this is a matter of style, as you shouldn't have any issues if you don't use them when they are not strictly required, although in order to be consistent, it's better to use them than not.
This is a pretty good article also. https://www.codecademy.com/blog/78
Hope this helps!
OP is asking about if semicolons are required in an import statement.
Use semi colons when declaring variables, returning something or making variable calls, as you are declaring a variable with the import it is my understanding that you should use a semicolon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With