2 ms·
Here's another neat example of short-circuit or: function getFoo(f) { if (f) { if (foos[f]) { return foos[f];
by andreyf 18y ago
Here's another neat example of short-circuit or:
function getFoo(f) {
if (f) {
if (foos[f]) {
return foos[f];
} else {
return f;
}
} else {
return "error";
}
}
Is (almost) the same as...
function getFoo(f) {
return foos[f] || f || "error";
}
The difference in behavior being if foos[undefined] is set...