Last active
June 29, 2018 17:41
-
-
Save edwingustafson/2a6ddfa178ecef4d07bdcba3892fb648 to your computer and use it in GitHub Desktop.
Condition assignment with and without variable bindings and logic
This file contains hidden or 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
// conditionally assign variable binding | |
let coinflip1; | |
if( Math.random() > 0.5 ) { | |
coinflip1 = 'heads'; | |
} else { | |
coinflip1 = 'tails'; | |
} | |
// conditionally assign constant binding | |
const coinflip2 = Math.random() > 0.5 ? 'heads' : 'tails'; | |
// awkward, but possible to perform logic in the branches via IIFE | |
const cointflip3 = Math.random() > 0.5 ? | |
'heads' : | |
(() => { | |
console.log('Ouch!'); | |
return 'tails'; | |
})() | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment