Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Can i force empty date object to be reassigned?

I am doing a to-do list, everything else works fine, but there's one issue that keeps bothering me. Since I don't want to set the date and the time as required input, so sometimes the date and time will be left blanket. But when I sorted the date ascending, the empty date's row will just pop up to the top. I hope it always is put to the bottom, no matter how I sort it. I tried to reassign the date to '2100-11-30T00:00:00'before compare function, but it's not working, and the console shows "Invalid Date". So I just wondering if there's any way to fix it? or Any solution to solve this problem?

const dateDown = document.querySelector(".dateDown")
dateDown.addEventListener("click", () => {

    let arrayList = JSON.parse(localStorage.getItem("theList"));
    arrayList.sort(function (a, b) {
        let aDate = new Date(a.date) + a.time;
        let bDate = new Date(b.date) + b.time;

        if (aDate === null) {
            aDate = new Date('2100-11-30T00:00:00');
        }
        console.log(aDate, bDate);
        if (aDate < bDate) {
            return 1;
        } else if (aDate > bDate) {
            return -1;
        } else if (aDate == bDate) {
            return 0;
        }
    })

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!