Since void 0
is undefined. Than this:
void 0 === data && ( data = 20 );
Is a very goofy way of writing this code:
if (data === undefined)
data = 20
So executed first comparison void 0 === data and if it is true it will execute the right side of the condition which assigns 20 to the data.
The code bellow basically assigns data variable a value 30 when data is undefined. Though again this code is pretty goofy, the reason being is that you don't need to set data = 30 in the true branch, you can just return 30... this code works because when you assign a varaible a vlue the result of the assignment is the value itself so this is what happens here, operation data = 30 returns 30, but you could just write data = typeof data === "undefined" ? 30 : data;
var b = function(data) {
data = typeof data === "undefined" ? data = 30 : data;
return data;
};
The best way I think would be the following:
var b = function (data) {
data = data || 30;
}