

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)

United States

ALT // Avoid making a property optional to support two separate scenarios. // Doing so redunces type safety. type User = { // Making id optional since unsaved users don't have an id yet. 👎 id?: number; name: string; email: string; } // Instead, declare separate types. Then each scenario is fully type safe. 👍 type User = { id: number; name: string; email: string; } // Separate type for unsaved users. // Deriving from the User type via Omit to keep types clean and lean. type UnsavedUser = Omit<User, "id">;
















