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

175
Vistas
Directly changing and then getting a returned closure variable

In a closure with internal variables, if I return the variable itself, I'm able to change its value directly. But if I add a getter to the closure, it doesn't output the new set value. But if I use a setter, then the getter outputs the correct value. When I 'change' the value of the returned variable, what exactly am I changing?

function money(){

    let usd=10;
    const getRate = () => usd;
    const setRate = (rate) => usd = rate;

    return {usd, getRate, setRate}
}

let m1 = money();

m1.usd = 20;
console.log(m1.getRate()) // Returns 10
console.log(m1.usd) // Returns 20

m1.setRate(30);
console.log(m1.getRate()) // Returns 30
about 4 years ago · Juan Pablo Isaza
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