Do i need to add semicolcon for constructor in javascript class?

I would like to know if I need to add a semicolon after the constructor. It seems like adding semicolons or not adding, both work.

function test() { }; function test2() {} 
+4
source share
4 answers

In short, you do not need to add a semicolon.

According to the article, which is fully devoted to the topic of semi-columnar necessity in JavaScript , all these are valid examples of lines without a semi-column:

 var a=1 var b=2 var c=3 // before if(condition) stuff() // after if(condition){ stuff() } // after minification if(condition){stuff()} 

This, on the other hand, will not work:

 a = b + c (d + e).print() 
+1
source

In javascript, if two JS statements are separated by a line, then the semicolon is present or not, it does not matter. If JS expressions are combined as in a mini file, then a semicolon is required, otherwise you will receive an error message.

0
source

JSLint clause - JSLint expects each expression to follow; except for, function, if, switch, try, and while. JSLint does not expect to see unnecessary semicolons or an empty statement.

In your case. I think there is no need to add a semicolon

0
source

In your example, a semicolon is not needed. Or, indeed, expected; the interpreter will ignore it.

But if you have to do this:

 var test = function() { return; }; 

... expected semicolon . Because you enter a semicolon, it is not needed (your interpreter will "fix" it if you do not leave it), but it generally recommended that you use it anyway.

The difference is that function name() {} is a compound statement, whereas var name = function() {}; is a simple ad.

Link: http://javascript.crockford.com/code.html

0
source

Source: https://habr.com/ru/post/1391063/


All Articles