I have this source code:
function findMessageErrors(btn) {
var error = "";
var message = $(btn).parent().siblings().find("textarea[name='message']").val();
if (message === "") {
error += "*Please enter a message.<br/>";
}
if (!$(btn).parent().siblings().find('input[name="agree"]').prop('checked')) {
error += "*Please agree.<br/>";
}
return error;
}
This gets minified. After minification, it looks like this in the Chrome Dev tools Sources tab:
function findMessageErrors(btn) {
var error = "";
return "" === $(btn).parent().siblings().find("textarea[name='message']").val() && (error += "*Please enter a message.<br/>"),
$(btn).parent().siblings().find('input[name="agree"]').prop("checked") || (error += "*Please agree.<br/>"),
error
}
I understand how the comma operator 'runs a series of expressions, in order, and then returns the result of the last of them' (from here). But I'm having a hard time understanding how those OR and AND operators are working in building that string that gets returned in the minified code.
Does anyone have a helpful way of reading that out loud that will help me understand how that works? I guess I don't see how 2 independent IF statements in the source gets minified into a series of && then ||. I don't want to have to look up the source every time I want to understand the logic of how the minified code works.