Last active
March 25, 2022 12:43
-
-
Save emilhein/c9f55109d235814778b069f282ae01ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const creator = ({ variableHere = 'no', notHere = 'some-default' }) => { | |
let myObject = { | |
id: 'someId', | |
...(variableHere && { variableHere }), | |
...(notHere && { notHere }), | |
}; | |
return myObject | |
} | |
let variableHere = 'yes' | |
let createdObject = creator({ variableHere }) | |
// Result: | |
// { id: 'someId', variableHere: 'yes', notHere: 'some-default' } | |
let createdObject2 = creator({ variableHere, notHere: null }) | |
// Result: | |
// { id: 'someId', variableHere: 'yes' } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment