Created
November 21, 2016 03:06
-
-
Save thejsj/b3e0e8d032374a707a418b3d9a7b86c5 to your computer and use it in GitHub Desktop.
Return vs Else Example
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
'use strict' | |
// All these functions behave the same way | |
const getHello = function (a) { | |
if (a === true) { | |
return 'hello' | |
} | |
else { | |
return 'wow' | |
} | |
} | |
const getHello = function (a) { | |
if (a === true) { | |
return 'hello' | |
} | |
return 'wow' | |
} | |
const getHello = (a) => { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions | |
if (a === true) return 'hello' | |
return 'wow' | |
} | |
const getHello = (a) => { | |
if (a) return 'hello' // Checks for truthy values instead of true | |
return 'wow' | |
} | |
const getHello = (a) => a ? 'hello' : 'wow' // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment