How to get the selected calendar date using Pikaday

I’m new to using a pre-made calendar such as Pikaday. I just can’t seem to grasp how to get the selected calendar date. The code I see online to do that just doesn’t work for me so I must be doing something wrong.

I am getting the error “field is not defined”.

Can someone please point me in the right direction? Thank you so much.

var picker = new Pikaday({
    field: document.getElementById('id_pikaday_datepicker'),
    onSelect: function(date) {
        field.value = this.getMoment().format('Do MMMM YYYY');
console.log(field.value);
    }
});```