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

324
Views
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 answers
Answer question

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 Report

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 Report
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!