const obj1 = { name: '🐶' };
const obj2 = { name: '🐱', owner: 'Ellie' };
if (obj1 || obj2) {
console.log('둘다 true!');
}
let result = obj1 && obj2;
console.log(result);
result = obj1 || obj2;
console.log(result);
function changeOwner(animal) {
if (!animal.owner) {
throw new Error('주인이 없어');
}
animal.owner = '바뀐주인!';
}
function makeNewOwner(animal) {
if (animal.owner) {
throw new Error('주인이 있어');
}
animal.owner = '새로운주인!';
}
obj1.owner && changeOwner(obj1);
obj2.owner && changeOwner(obj2);
console.log(obj1);
console.log(obj2);
obj1.owner || makeNewOwner(obj1);
obj2.owner || makeNewOwner(obj2);
console.log(obj1);
console.log(obj2);
let item = { price: 1 };
const price = item && item.price;
console.log(price);
function print(message) {
const text = message || 'Hello';
console.log(text);
}
print();
print(undefined);
print(null);
print(0);