Skip to content

Instantly share code, notes, and snippets.

@bradydowling
Last active August 29, 2015 14:12
Show Gist options
  • Save bradydowling/ea419dcf149726244a10 to your computer and use it in GitHub Desktop.
Save bradydowling/ea419dcf149726244a10 to your computer and use it in GitHub Desktop.
Using Function Expressions in JavaScript
// 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