Last active
February 26, 2017 19:17
-
-
Save y13i/33784c22441124e73586d3a8c9396c35 to your computer and use it in GitHub Desktop.
if statement vs ternary operator
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 num = Math.floor(Math.random() * 10); | |
let evenOrOdd: string; | |
if (num % 2 === 0) { | |
evenOrOdd = 'even'; | |
} else { | |
evenOrOdd = 'odd'; | |
} | |
console.log(`${num} is an ${evenOrOdd} number.`); |
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 num = Math.floor(Math.random() * 10); | |
const evenOrOdd = (num % 2 === 0) ? 'even' : 'odd'; | |
console.log(`${num} is an ${evenOrOdd} number.`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment