Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Simpler way to write this snippet? Reply To: Simpler way to write this snippet?

#151194
__
Participant

I’m somewhat confused about the updated syntax…specifically this.then = this.then || 0;

We’re checking to see if then is already defined before defining it: so, on the first use then will be undefined, so that statement will assign the initial value 0. Once we do then = now, then will have a value, and so that statement will leave it with its own value. It’s similar to doing:

if( ! this.then ){
    this.then = 0;
}