Skip to content

Instantly share code, notes, and snippets.

View igeligel's full-sized avatar
🤷‍♀️
Shifting bits around the world

Kevin Peters igeligel

🤷‍♀️
Shifting bits around the world
View GitHub Profile
const basePerson = {
firstName: "Max"
};
const person = {
...basePerson,
lastName: ""
};
const basePerson = {
firstName: "Max"
};
const person = Object.assign({}, basePerson, { lastName: "" });
const condition = true;
const result = condition && { lastName: "" };
console.log(result);
// Will log { lastName: "" }
const a = false;
const b = true;
const result = a && b;
console.log(result);
// Will log false
const c = false;
const d = false;
const result = c && d;
console.log(result);
const a = true;
const b = true;
const result = a && b;
console.log(result);
// Will log true
const a = true;
const b = "Magic String";
const result = a && b;
console.log(result);
// Will log "Magic String"
const condition = getCondition();
const additionalCondition = getAdditionalCondition();
const person = {
firstName: "Max",
...(condition && { lastName: "" }),
...(additionalCondition && { addition: "" })
};
const person = {
firstName: "Max"
};
const condition = getCondition();
const additionalCondition = getAdditionalCondition();
if (condition) {
person.lastName = "";
}
const person = {
firstName: "Max"
};
const condition = getCondition();
if (condition) {
person.lastName = "";
}
const person = {
firstName: "Max"
};
person.lastName = "";