Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript 1 Liner Question [duplicate]

Tags:

javascript

Possible Duplicate:
What does “options = options || {}” mean in Javascript?

What does the following line of Javascript code do?

var somevar = window.somevar || {};
like image 552
VinnyD Avatar asked Mar 06 '26 22:03

VinnyD


1 Answers

It sets somevar to window.somevar if window.somevar exists and is not boolean false, otherwise it sets it to an empty object {}

It's a common idiom for handling variables which may not have been set.

like image 125
Rob Agar Avatar answered Mar 08 '26 10:03

Rob Agar



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!