Will there be problems if not using semicolons in javascript?

Question:

I would be happy with an example if the answer to my question is positive. So far, I have not seen a single use of this sign where it could not simply be skipped. The interpreter also never gave an error due to the lack of a semicolon.

Answer:

In a for loop, it cannot be skipped.

for(объявление переменных; условие; обновление счетчика)

And also if you want to make an empty loop body:

while(true);
console.log(1) // Без точки с запятой это попадёт в тело цикла

Another case, when assigning without a semicolon at the end, you can grab something extra, for example, an expression in brackets can be understood as a function call:

 const i = 0 (2+1).toString();

Or, for example, you can lose the regex:

const i = 0
/[a-z]/g.exec(i)

or you want to make an array, and the interpreter might think that you want to get some property from the end of the previous line:

console.log(2)
[1,2].map(num => num*2);

You can also come up with a case when a unary plus turns without a semicolon into an addition

Scroll to Top