Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 24, 2014 23:24
Javascript Short-Hand IF Within Object Notation
<script type="text/javascript">
// Create an array of friends.
var arrFriends = new Array(
"Molly",
"Sarah",
"Dave",
"Luke"
);
// Get the day of the week.
var intDayOfWeek = (new Date()).getDay();
// Figure out which friend to call based on
// the given day of the week. Call Luke on saturday.
// For every other day, call Molly (my girlfriend).
var strFriendToCall = arrFriends[ ( intDayOfWeek == 6 ) ? 3 : 0 ];
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment