Last active
August 29, 2015 14:12
-
-
Save bradydowling/ea419dcf149726244a10 to your computer and use it in GitHub Desktop.
Using Function Expressions in JavaScript
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
// Using a function expression, I can assign different values to a variable conditionally. | |
var day = 'Friday'; | |
if (day === 'Friday') { | |
var myGreeting = function () { | |
return "Happy Friday!"; | |
} | |
} | |
else { | |
var myGreeting = function () { | |
return "Good morning!"; | |
} | |
} | |
console.log(myGreeting()); // Logs "Happy Friday!". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment