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

177
Vistas
Change original variable value by changing value of passed function parameter

Is it possible to change the variable value with function like example below? Whenever I change the passed parameter value the original value doesn't change. Why is this happening?

let b = 3;
function t(n) {
    n = 5; 
}

t(b)
console.log(b) // still 3

I know this can be done like this, but I am wondering why the example above wont work.

let b = 3;

function t() {
    return 5;
}

b = t();
console.log(b)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Passing scalar values to function will pass them by value, not by reference.

One solution would be to pass it as object:

let b = {value: 3};

function t(n) {
    n.value = 5; 
}

t(b);
console.log(b.value);

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