0

I have a function that generates filenames using the data and time. In the code below, I concatenate the date and time together in separate statements. If I run the code as so below, will the fileName be returned before either the date or time can be concatenated? If I return everything in one line, will that ensure the filename will be complete before being returned?

function generateFileName()
{
    var date = new Date();

    var fileName = "scoreboard-";
    //date
    fileName += date.getMonth()+'-'+date.getUTCDate()+'-'+date.getUTCFullYear()+'-';
    //time
    fileName += date.getHours()+'-'+date.getMinutes()+'-'+date.getSeconds();

    //return fileName;
}
1
  • There's nothing asynchronous going on there ? Commented Dec 31, 2014 at 20:30

1 Answer 1

2

The Date constructor and all assignments are synchronous operations. When you return fileName it will be the full file name as you have constructed it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.