Semicolon (;) in ECMAScript 6 is no longer needed? [duplicate]

7

When using ECMAScript 6 (ES6) is it no longer necessary to use a semicolon (;) at the end of each line of code?

    
asked by anonymous 29.12.2016 / 18:03

2 answers

10
The semicolon (semicolon) was never mandatory at the end of lines, its use is another, it is meant to separate expressions that are on the same line or within a for .

Note that in JavaScript line breaks also have a separating effect, see:

var i = 0; i++ // ponto e virgula é obrigatório

var i = 0      // ponto e virgula é opcional pois estão em linhas diferentes
    i++
  

Note ¹: for has 3 expressions as explained by @Sergio and therefore requires two ; :

for ([inicialização]; [condição]; [expressão ao final de cada loop])
     

for does not use ; when using in (unless you wanted to add expressions for additional operations):

for ([variável] in [objeto que terá as propriedades iteradas])
     

or of :

for ([variável] of [objeto que terá os valores iterados])
     

Note ²: This occurs in other languages too

Sources:

29.12.2016 / 18:08
8

Does not have to do with ES6 use or not comma or not, is "a matter of religion" :)
That is: It's a question of code style.

; is a symbol with JavaScript functionality, that of separating statements , in some cases it can not be ignored, for example: for (var i = 0; i < 10; i++) , but at the end of the line it is optional, since that there is a line break.

    
29.12.2016 / 18:11