'Uncaught SyntaxError: redeclaration of const check

I am working in django and i have written a simple code for dark and light theme, it is working perfectly, but when i inspect my page, it shows an error 'Uncaught SyntaxError: redeclaration of const check', so this is my js code, please tell me how i get rid of this error.

const check=document.getElementById("check")

if (localStorage.getItem('darkMode')===null){
    localStorage.setItem('darkMode', "false");
}

const link = document.createElement('link');
link.rel = 'stylesheet';

document.getElementsByTagName('HEAD')[0].appendChild(link);

checkStatus()

function checkStatus(){
    if (localStorage.getItem('darkMode')==="true"){
        check.checked = true;                           
        link.href = './static/css/modes/dark-mode.css';                   
    
    }else{
        check.checked = false;                         
        link.href = './static/css/modes/light-mode.css';
    }
}

function changeStatus(){                                
    if (localStorage.getItem('darkMode')==="true"){     
        localStorage.setItem('darkMode', "false");      
        link.href = './static/css/modes/light-mode.css';
    } else{
        localStorage.setItem('darkMode', "true");       
        link.href = './static/css/modes/dark-mode.css';
    }
}

please help me



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source