Here is my code:
var pickupdate;
$(function(){
  $.datepicker.setDefaults(
    $.extend( $.datepicker.regional[ '' ] )
  );
  $( '#pickupdate' ).datepicker( {
    dateFormat: 'yy-mm-dd',
    maxDate: "+3m",
    minDate: 0,
    onSelect: function() { 
      pickupdate = $(this).datepicker( 'getDate' ); 
      alert(pickupdate)
 }
  });
});
console.log(pickupdate)
The alert (within function) works while the console.log (outside function) shows pickupdate as undefined. What am I doing wrong?
 
    