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

267
Vistas
Pass by Value and Pass by Reference in Javascript

Now that I've been working on Angular2 for almost 3 months, I've encountered a few scenarios which led me to wonder how does this happen ?

In the case of special this keyword it's obvious that it's passing a reference or instance of the related DOM Object or Class for Example.

But then there is another thing called ControlGroup which also does the same whenever it's assigned to another variable. And both the variables have access to same instance of that ControlGroup.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Objects and arrays are passed by reference. Primitive values like number, string, boolean are passed by value. A reference to an object is also a primitive type and passed by value like other primitive types, but the object it refers to is still passed by reference.

This is not Angular or TypeScript specific, just how JavaScript works.

over 4 years ago · Santiago Trujillo Denunciar

0

A tweak in case you know what are you doing, could be as follows:

pseudocode:

foo() {
  int num = 1;
  bar(num);
  // num is 2!!
}
bar(int arg byRef) {
  arg = 2
}

typescript:

function foo() {
  let num = 1;
  (() => {
    const ret = bar(num) as any;
    num = ret.arg;
  })();
  // num is 2!!
}
function bar(arg) {
  arg = 2;
  return { arg };
}
over 4 years ago · Santiago Trujillo 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