||, &&
Longhand:
var x, y;
if (x !== null || x !== undefined || x !== '') {
y = x;
}
Shorthand:
const y = x || undefined;
x && (y = x);
Decimal base exponents
Longhand:
for (let i = 0; i < 10000; i++) {}
Shorthand:
for (let i = 0; i < 1e7; i++) {}
// All the below will evaluate to true
1e0 === 1;
1e1 === 10;
...
Object Property Shorthand
Longhand:
const obj = { key: key, value: value };
Shorthand:
const obj = { key, value };
Default Parameter Values
Longhand:
function volume(l, w, h) {
if (w === undefined) w = 3;
if (h === undefined) h = 4;
return 1 * w * h;
}
Shorthand:
volume = (1, w = 3, h = 4) => (1 * w * h);
volume(2);
Template Literals
Longhand:
const welcome = 'You have logged in as ' + first + ' ' + last + '.'
const db = 'http://' + host + ':' + port + '/' + database;
Shorthand:
const welcome = `You have logged in as ${first} ${last}`;
const db = `http://${host}:${port}/${database}`;