Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
Uncaught TypeError: setting getter-only property "selectedProjectId"

Trying to set this variable to an element's id number, but I can't make sense of this error statement.

{Uncaught TypeError: setting getter-only property "selectedProjectId"}

I declared the variable here.

const LOCAL_STORAGE_LIST_KEY = 'project.lists';
const LOCAL_STORAGE_SELECTED_LIST_ID_KEY = 'project.selectedProjectId';
const projects = JSON.parse(localStorage.getItem(LOCAL_STORAGE_LIST_KEY)) || [];
const selectedProjectId = localStorage.getItem(LOCAL_STORAGE_SELECTED_LIST_ID_KEY);

function save() {
    localStorage.setItem(LOCAL_STORAGE_LIST_KEY, JSON.stringify(projects));
    localStorage.setItem(LOCAL_STORAGE_SELECTED_LIST_ID_KEY, selectedProjectId);
}

export {
    projects,
    save,
    selectedProjectId,
}

I try to assign it a different value here.

projectList.addEventListener('click', e => {
    if (e.target.tagName.toLowerCase() === 'li') {
        console.log(e.target.dataset.projectId);
        console.log('works');
        selectedProjectId = e.target.dataset.projectId;
        saveAndRender();
    }
});

I'm following webdev simplified's tutorial on a better to-do-list in js. I'm following pretty closely, but mine keeps throwing the type error. How do I fix this? Any advice would be helpful. For more clarification, I am also using webpack if that is important.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const cannot be assigned to a new value. Use let instead.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda