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

147
Vistas
Cannot use function to update object

I've created a function change which can be used to change the name of the object person.

There is one argument for the function and this argument would be the new name for the object.

But the new name I pass into this argument becomes ...is not defined, what am I missing here?

Edited thisIsNewName is a string and this is to replace Ali.

const person = {
  name: 'Ali',
  Age: '18'
}

function change(text) {
  person.name = text;
}

change(thisIsNewName);

console.log(person.name);

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

thisIsNewName is a string and this is to replace Ali.

No, it's not.

thisIsNewName is not defined in your code.

Either define the variable and assign a string

const person = {
  name: 'Ali',
  Age: '18'
}

function change(text) {
  person.name = text;
}

const thisIsNewName = 'newName';
change(thisIsNewName);

console.log(person.name);

or call the function with a string literal

const person = {
  name: 'Ali',
  Age: '18'
}

function change(text) {
  person.name = text;
}

change('thisIsNewName');
console.log(person.name);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are trying to pass argument that you did not define. You can create variable or you can pass directly string to it

const person = {
  name: 'Ali',
  Age: '18'
}

function change(text) {
  person.name = text;
}

let thisIsNewName = 'ALI2';
change(thisIsNewName);


//Or you can pass directly string
//change("thisIsNewName");


console.log(person.name);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should pass the name as a string if you meant it like this -> change("thisIsNewName") But if you want to pass a variable to the function then define it before using: let thisIsNewName = "new name"

const person = {
  name: 'Ali',
  Age: '18'
}

function change(text) {
  person.name = text;
}

change("thisIsNewName"); //*

console.log(person.name);

or

    const person = {
      name: 'Ali',
      Age: '18'
    }

    function change(text) {
      person.name = text;
    }
    
    let thisIsNewName = "new name";//*
    change(thisIsNewName);

    console.log(person.name);

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