I have a uglified JS file where I want to get the beautified version and then uglify it with grunt again. And I expect it to be the same as the first uglified file.
But when I do it one part, with the 'if', is different.
This is a part of the uglified file:
...function sendRequest(requestParams){if(Object.keys(requestParams).length>=1){$.ajax({type:"POST",url:VideoSearchUrl,data:requestParams,dataType:"xml"}).done(function(xmlDoc){buildResult($(xmlDoc)),responses++,requests==responses&&postSearchActions()})}}function...
But the uglified version from the beautified file look like this:
...function sendRequest(requestParams){Object.keys(requestParams).length>=1&&$.ajax({type:"POST",url:VideoSearchUrl,data:requestParams,dataType:"xml"}).done(function(xmlDoc){buildResult($(xmlDoc)),responses++,requests==responses&&postSearchActions()})}function...
Why is the 'if' dropped? In an online uglifier it is still there.
Or does it mean the same?
This is correct due to Short Circuit Evaluation.
(Emphasis by me)
Why bother?
true&&expression
is shorter thanif(true){expression}
(every byte counts)