Just learned JavaScript has logical OR assignment and logical AND assignment! 🔥
Logical AND assignment:
x &&= "x is truthy" // assigns if the left side is truthy
Logical OR assignment:
x ||= "x is falsy" // assigns if the left side is falsy
#javascript
ALT const user = { name: "Cory", email: '' };
// Logical AND examples:
// ---------------------
// Set name to 'known' if name is truthy
user.name &&= "known";
console.log(user.name); // known (because name is truthy)
// Set email to 'known' if email is truthy
user.email &&= 'known';
console.log(user.email); // '' (because email is falsy)
// Logical OR examples:
// ---------------------
// Set name to unknown if name is falsy
user.name ||= "unknown";
console.log(user.name); // Cory (because name is truthy)
// Set email to 'unknown' if email is falsy
user.email ||= 'unknown';
console.log(user.email); // unknown (because email is falsy)
The Bridge pattern is a structural design pattern that allows you to separate a big class or set of related classes into two different domains: abstraction and implementation.
Learn how to implement it: jmalvarez.dev/posts/bridge-p…#TypeScript#javascript#webdevelopment