-1

Why are multiple semicolons allowed on one line in Javascript? What is really happening here?

var x = 5;;;;;;;;;;
console.log(x);;;;;
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Zamboni
  • 315
  • 1
  • 3
  • 12
  • https://stackoverflow.com/questions/20907389/double-semicolons-syntax-in-javascript. The semicolon is just a separator, you can habe multiple of the same like you can have multiple new lines – Marged Sep 14 '18 at 04:13

1 Answers1

3

A semi colon is a statement separator. By itself it creates an empty statement which, if you can say it is "executed" has no effect.

Multiple semicolons in a row simply create multiple consecutive empty statements and serve no practical purpose in code terms.

Deliberate use of empty statements may cause confusion and usually have alternatives. For example:

if( condition)
    ;
else {
   // do something
}

is more clearly coded as

if( !condition) {
    // do something
 }
traktor
  • 17,588
  • 4
  • 32
  • 53