destructuring falsy and null with default parameters

Only undefined will cause the default initialiser to run in destructuring and function parameter targets. If you want to fall back to your default for all falsy values, use the good old || operator instead:

const email = person.email || '';

Or target a mutable variable and use logical OR assignment afterwards:

let { email } = person;
email ||="";

Leave a Comment