When using ECMAScript 6 (ES6) is it no longer necessary to use a semicolon (;) at the end of each line of code?
When using ECMAScript 6 (ES6) is it no longer necessary to use a semicolon (;) at the end of each line of code?
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 usingin
(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:
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.