here is the example. i have it always return true
const lastDiscountCode = moment(202352,"YYYYWW");
const currentWeek = moment().format("YYYYWW");
alert(moment(lastDiscountCode).isBefore(moment(currentWeek)));
In moment(202352, "YYYYWW").format("YYYYWW") what you enter inside the moment function takes the data and converts it into date format first, and then that date is formatted into 'YYYYWW'. So what you should be doing is enter a date inside the moment and then format it into 'YYYYWW'
const lastDiscountCode = moment('2024-09-28').format("YYYYWW");
const currentWeek = moment().format("YYYYWW");
console.log(currentWeek); // "202204"
console.log(lastDiscountCode); // "202439"
alert(moment(lastDiscountCode).isBefore(moment(currentWeek))); // false
You have to use .format("YYYYWW") on lastDiscountCode :
const lastDiscountCode = moment(202352,"YYYYWW").format("YYYYWW");
const currentWeek = moment().format("YYYYWW");
console.log(moment(lastDiscountCode).isBefore(moment(currentWeek)));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>