JavaScript Assignments Ternary
JavaScript Assignments Ternary
Basic Level
Ternary Operator
1. Create a function `getGreeting` that takes a boolean `isMorning` as input and returns:
Example:
};
let message;
message = "Loading...";
} else {
message = "Loaded!";
}
Optional Chaining
3. Use optional chaining to retrieve the `email` of a user safely without causing an error:
const user = {
profile: {
email: "[email protected]",
},
};
console.log(user.profile?.email); // "[email protected]"
console.log(user.account?.email); // undefined
4. Write a function `getUserCity` that takes a `user` object and returns the `city` from `address`
Example:
};
console.log(getUserCity(user)); // "Unknown"