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

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

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