Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

325
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda