Madhusudan Iyengar
Madhusudan Iyengar

Reputation: 23

JavaScript - How to store and use return value of the function in a variable

var today = new Date();
var tomorrow = today;
tomorrow.setDate(tomorrow.getDate() +1);

function formatDateToString(date) { 
  var dd = (date.getDate() < 10 ? '0' : '') 
      + date.getDate(); 

  return dd;
}

how can I store and use the return value in a variable?

Upvotes: 0

Views: 4249

Answers (1)

wbevan91
wbevan91

Reputation: 11

Since the function is returning a value you can assign the returned value to the variable like this:

var returned = formatDateToString(date);

Upvotes: 1

Related Questions