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

94
Views
Problem with variable scoping in javascript

I was trying to understand the variable scoping in JavaScript. But I didn't understood why below code behaving different from the expected behavior.

'use strict';
function C() {
  console.log(a);
}

function B() {
  let a = 'printing A from B()';
  C();
}

function A() {
  let a = 'printing A from A()';
  B();
}

const a = 'printing A from global context';
A(); // output getting: 'printing A from global context': CORRECT
B(); // output getting: 'printing A from global context' but expected : 'printing A from B()'
C(); // output getting: 'printing A from global context' but expected : 'printing A from A()'

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The output is correct. Functions A and B both have a different scoped a variable, but C has no access to their scope - only to the global scope - which defines const a

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!