Javascript date object confusion

Function parameters allow a function to operate on different inputs. In this case, inDate is the local name given to the argument supplied when you call the function. So the function should be:

function dateUS(inDate) {
    document.write(getMonth(dateUS) + "" + dateUS.getDate() + "" + dateUS.getFullYear());

If you want to write today’s date, you call the function this way:


There isn’t enough information in the question to explain why undefined is being shown after the date. My guess is you’re doing something like:


This would be appropriate if dateUS returned its result instead of writing it itself. That probably would be a better way to define it, but it’s not how you did it.

Leave a Comment