JavaScript Enumerations

Rather than defining many JavaScript 'constants', e.g.

 

var CONST_DAY_OF_WEEK_MONDAY = 1;

var CONST_DAY_OF_WEEK_MONDAY = 2;

var CONST_DAY_OF_WEEK_MONDAY = 3;

etc.

You can alternatively declare:

var daysOfWeek= { monday: {}, tuesday: {}, wednesday: {} }; // etc.

And then you can use instead of integer constants, for example a function to alert if a day is Monday:

function alertMondays(today){

 if (today == daysOfWeek.monday)

   alert('Bad case of the Mondays');

}