Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this Javascript Snippet does (start of jQuery migration file)

I have found this piece of code in jQuery Migrate v1.1.1

jQuery.migrateMute===void 0&&(jQuery.migrateMute=!0),function(e,t,n){/* anything */}

And I really wonder about 2 things:

1) What does ===void 0 mean?

2) Why these conditions are followed by a comma? My tests showed me it will always get executed.

Its just not I really need to know,but i am really interested, because I thought I knew everything about JS. ;)

like image 831
s0urce Avatar asked Apr 20 '15 06:04

s0urce


1 Answers

void 0 will yield undefined, as will void X for any X; it is shorter, and cannot get redefined like undefined can. So ===void 0 compares jQuery.migrateMute with undefined.

!0 is true.

Thus, the "translation" of jQuery.migrateMute===void 0&&(jQuery.migrateMute=!0) is:

if (jQuery.migrateMute === undefined) {
  jQuery.migrateMute = true;
}

Then the stuff after the comma executes, independently from this.

like image 169
Amadan Avatar answered Nov 15 '22 07:11

Amadan