I encountered an error message saying "Uncaught ReferenceError: Cannot access 'Q12' before initialization" while working in the changeCssClassIfOldAndNewValuesAreDifferent function. Any thoughts on what might be causing this issue? Thank you.
const formController = (function () {
return {
'changeCssClassIfOldAndNewValuesAreDifferent': changeCssClassIfOldAndNewValuesAreDifferent
};
const formScope: any = $("form#userAnswerForm");
const Q12: any = $('.persistable[id=Q12]', formScope);
const Q23: any = $('.persistable[id=Q23]', formScope);
function changeCssClassIfOldAndNewValuesAreDifferent() {
$('input.persistable, select.persistable').not(Q12) //<---Reference Error
.each(function () {
console.log('each persistable input and select listeners (change, mouseout)');
const thisPersistable: any = $(this);
const Q12_or_Q23_is_not_empty: boolean = !commonUtility.isEmpty(Q12) &&
!commonUtility.isEmpty(Q23);
...
...
});
}
})();
$(function(){
formController.changeCssClassIfOldAndNewValuesAreDifferent();
});