The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Days of the Week Reply To: Days of the Week


My Question is can these two lines be combined?

very simply:

var weekday = new Date().getDay();

This is called “method chaining.” Since functions are first-class (and, since functions are objects) in javascript, this will work any time the function/method on the left (e.g., Date) returns an object that has the method/property on the right (e.g., getDay).