View Full Version : Breakdown of statement.

08-30-2008, 02:08 PM
I've tried to break down the following statement.

var d=new Date();
//So var means variable. d is the name of the variable. = is what the variable equals. duh ... new Date is a javascript function that gets the current date but I don't understand what () is?

theDay=d.getDay(); // On this

//theDay is the name of the next variable, d is the name of the variable i've created above and getDay turns it into a number? Still don't understand the ()

I can get this script to work ... I just want to understand WHY i can get it work .

Thanks in advance.

Philip M
08-30-2008, 05:22 PM
Any JavaScript book or web site will explain this.

var d = new Date() - if no parameters are supplied within the brackets JavaScript creates an object for today's date according to the time on the local machine.

You could also supply parameters:-
var d = new Date(milliseconds)
var d = new Date(dateString)
var d = new Date(yr_num, mo_num, day_num [, hr_num, min_num,
sec_num, ms_num])

e.g. var d = new date(2008,7,30) // 30th August 2008

All dates are calculated in milliseconds from 01 January, 1970 00:00:00 Universal Time (UTC) with a day containing 86,400,000 milliseconds.

var theday = d.getDay() invokes a method of the date object which returns an integer (0 for Sunday through 6 for Saturday) representing the day of the week.

08-31-2008, 02:23 AM
Thanks for your help :)

Makes sense now.