Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Declaring a variable twice in the same line -- what does it mean (eg. Var x = this.time = this.time || this.time(); )

Tags:

javascript

I recently found the following code, but I have never seen JS like this before. What does it mean, and does it work?

Var x = this.time = this.time || Data.now(); 
like image 830
ke.li Avatar asked Nov 30 '25 16:11

ke.li


1 Answers

This code is a short form of,

this.time = this.time || Data.now();
Var x = this.time; 

But you have to be careful while using this way of coding in other aspects like,

var a = b = 10;

Because here in the above case b will become a global variable.

like image 191
Rajaprabhu Aravindasamy Avatar answered Dec 02 '25 07:12

Rajaprabhu Aravindasamy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!