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

114
Views
¿Se crea un cierre solo cuando una función interna devuelve algo?

He estado jugando un poco con los cierres y me cuesta entender cuál es la diferencia entre el alcance léxico y los cierres.

En los ejemplos a continuación, ambas funciones secundarias pueden alcanzar la variable a gracias al alcance léxico. Ahora me pregunto dónde se crea exactamente el cierre en el segundo ejemplo. ¿Se debe a que childFunc() se devuelve directamente, o se debe a que childFunc() se almacena en una variable child separada antes de ejecutarse?

Ejemplo 1: Sin cierre

 function parentFunc() { let a = 10; function childFunc() { console.log(`hey from child func Mr. ${a}`); a++; } childFunc(); } console.dir(parentFunc) //closure not part of the Scopes parentFunc() //doesn't increment a parentFunc()

Ejemplo 2: Cierre

 function parentFunc() { let a = 10; return function childFunc() { console.log(`hey from child func Mr. ${a}`); a++; } } const child = parentFunc() child(); // increments a child(); console.dir(parentFunc) //closure is part of the scopes
about 4 years ago · Juan Pablo Isaza
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!