2

So, I found a function in Stack Overflow a few days ago and I'm trying to understand it because I want to adapt it and apply it to my project. It's a function by Murplyx and it's in the 3rd answer of this question: find the time left in a setTimeout()?

My doubtfulness instantly begins when I start reading the function. The first statement is var id, started, remaining = delay, running. What does this mean? Also, why don't any of the statements have a semicolon at the end? The last question is probably dumb but I've always been advised use semicolons because otherwise it wouldn't work.

cabralpinto
  • 1,814
  • 3
  • 13
  • 32
  • 2
    For the `semicolon` part http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript – Ashraf Purno Sep 10 '15 at 11:06

1 Answers1

6

The line

var id, started, remaining = delay, running;

is identical to simply

var id;
var started;
var remaining = delay;
var running;

It's a shorthand to declare multiple variables at once.

As for semicolons, Javascript has something called automatic semicolon insertion (ASI), see this question, for example. Not a style I would recommend since it's easy to let in unintentional quirks, but your mileage may vary.

Community
  • 1
  • 1
Etheryte
  • 24,589
  • 11
  • 71
  • 116