title | datePublished | cuid | slug |
---|---|---|---|
The JavaScript substitution for IF with AND (&&) operator |
Sun Jul 21 2024 12:45:20 GMT+0000 (Coordinated Universal Time) |
clyvjwdyd00010amg3xz949l2 |
the-javascript-substitution-for-if-with-and-operator |
The && operator unique to JavaScript.
With it you can quickly go from this
function visitSite(user) {
if (user.isLoggodIn) {
console.log(`You are $ {user.name}`)
}
console.log (“Welcome”);
}
To this:
function visitSite(user) {
user.isLoggodIn && console.log(`You are ${user.name}`);
console.log(‘Welcome’);
}