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

326
Visualizações
Cannot find name `data`, but it's defined

I have the following error: "Cannot find name 'data'.", but I have defined it.

const initialState = () => {
  try {
    const data = window.localStorage.getItem('auth');
  } catch (e) {
    const data = null;
  }

  if (!data) {
    return {
      matrixIsAuthenticated: false,
      matrixUserId: null,
      matrixAccessToken: null,
    };
  } else {
    return data;
  }
};
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should define data variable outside try block first with let and give it value inside try only after that.

about 4 years ago · Juan Pablo Isaza Relatório

0

First, you need to understand the scope of a block of code. Once you define a variable inside the try block it cannot be accessed outside of it. similar case for the catch also.😇

Solution 01: Define it outside of the try-catch block. Also, use let since const cannot assign a value twice.

Solution 02: move the whole code into the try-catch block.

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