How to Pass variable from variables from one function to another

I have this code in view blade using JQuery to pass variables received from JSON:
I am using JQuery-UI datepicker

    < script type = "text/javascript" >
      var holidayDays = [];
      var weekendInclusives;
      var holidayInclusives;
      $(document).ready(function() {
        $(document).on('change', '#leave_type', function() {
        var air_id = $(this).val();

        var a = $(this).parent();
        $('#weekendinclusive').val('');
        $('#holidayinclusive').val('');
        $('#leave_days').val('');
        $('#resumption_date').val('');

        $.ajax({
          type: 'get',
          url: '{{ route('
          get.leavecounts.all ') }}',
          data: {
            'id': air_id
          },
          dataType: 'json', //return data will be json
          // console.log("Its Change !");
          success: function(data) {
            $('#weekendinclusive').val(data.weekendinclusive);
            $('#holidayinclusive').val(data.holidayinclusive);
            holidayDays = data.nationalholidays;
            weekendInclusives = parseInt($("#weekendinclusive").val());
            holidayInclusives = parseInt($("#holidayinclusive").val());
          },
          error: function() {

          }
        });
      });
    }); <
    /script>
    <input type="hidden" id="weekendinclusive" class="form-control" value="0">
    <input type="hidden" id="holidayinclusive" class="form-control" value="0">

I want to pass the values of weekendInclusives and holidayInclusives to the if statement in the function below, but I found out that it’s not being implemented:

    < script type = "text/javascript" >
      $(document).ready(function() {

        function noWeekendsAndHolidays(date) {
          var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
          //if u have to disable a list of day
          var removeDays = holidayDays;
          if ($.inArray(ymd, removeDays) >= 0) {
            return [false];
          } else {
            //Show accept sundays
            var day = date.getDay();
            return [(day == 1 || day == 2 || day == 3 || day == 4 || day == 5)];
          }
        }

        function noHolidays(date) {
          var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
          //if u have to disable a list of day
          var removeDays = holidayDays;
          if ($.inArray(ymd, removeDays) >= 0) {
            return [false];
          }
        }

        let dateOpts = {
          dateFormat: 'dd-mm-yy',
          changeMonth: true,
          changeYear: true,
          showAnim: 'slideDown',
          duration: 'fast',
          minDate: 1,
          setDate: new Date(),
          yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
        };

        if (weekendInclusives == 0 && holidayInclusives == 0) {
          dateOpts.beforeShowDay = noWeekendsAndHolidays;
        } else if (weekendInclusives == 0 && holidayInclusives == 1) {
          dateOpts.beforeShowDay = noHolidays;
        } else if (weekendInclusives == 1 && holidayInclusives == 0) {
          dateOpts.beforeShowDay = $.datepicker.noWeekends;
        }

        $('.commencement_date').datepicker(dateOpts).datepicker('setDate', '1');
      }); <
    /script>

I want to pass the values of #weekendinclusive and #holidayinclusive each time:

$(document).on('change', '#leave_type', function() {

onchange to the if statement in the datepicker… Also, the if statement should take the new values of #weekendinclusive and #holidayinclusive onchange #leave_type

How do I achieve this?

Thanks