Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does import statement need semicolon actually?

Tags:

ecmascript-6

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?

like image 673
ggrr Avatar asked Nov 18 '16 03:11

ggrr


People also ask

Is semicolon mandatory in Python?

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.

Do return statements need a semi colon?

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.

Is semicolon mandatory in React JS?

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.

Are semicolons necessary 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.


2 Answers

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!

like image 86
Karel Tamayo Avatar answered Oct 27 '22 11:10

Karel Tamayo


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.

like image 2
Jeremy Avatar answered Oct 27 '22 11:10

Jeremy