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

158
Views
Variable defined inside conditional not available outside

I know this is super basic but I cannot figure out why it is not working. I was expecting to see the element .basic_form logged in the last console.log. Instead I get the following:

if ( typeof basic_form === 'undefined' || basic_form === nulll ){
        console.log( 'not defined yet' );
        let basic_form = document.querySelector( '.basic_form' );
        console.log( basic_form) ;
    }
    console.log( basic_form );

Output:
1> not defined yet
2> the element .basic_form
3> Uncaught ReferenceError: basic_form is not defined (???)

Any insights would be greatly appreciated!

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Variable declared inside block are not accessible outside. You can find more on this Variable scope and closure.

about 4 years ago · Santiago Trujillo Report

0

basic_form it's defined inside the if statement you need to define it outside. I think it should be like this.

let basic_form = document.querySelector( '.basic_form' );

if ( typeof basic_form === 'undefined' || basic_form === nulll ){
        console.log( 'not defined yet' );
        console.log( basic_form) ;
    }
console.log( basic_form );

about 4 years ago · Santiago Trujillo 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!