3 ms·
JS novice here. Is this an idiomatic way to conditionally perform an operation in JS? It saves typing, but if(){} is much more explicit. a && this.oo.push(x.
by braindongle 9y ago
JS novice here. Is this an idiomatic way to conditionally perform an operation in JS? It saves typing, but if(){} is much more explicit.
a && this.oo.push(x.V.TH);
- adtac 9y agoThat's minification. The actual source code almost certainly does `if (a) { ... }`, but the minifier will shorten that into `a&&...`, thereby saving multiple bytes. Accumulate this over different if-clauses, and you're looking at serious savings.
- braindongle 9y agoAh, I see. Thanks. Interesting. The minifier must be smart enough to know that you're not doing anything with the return value, since the two aren't equivalent in that respect. false && console.log('foo'); //false if(false){ console.log('foo') }; //undefined
- rcfox 9y agoNot for user-written code, but most websites run their Javascript through tools to condense it so that the download size is smaller.