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

152
Views
matriz javascript pasada por referencia pero

¿Por qué console.log(a) no devuelve el mismo resultado [1, 2, 3, 4] que console.log(b)?

 function test(c, d) { c = [1, 2, 3, 4]; d.push(4); } a = [1, 2, 3]; b = [1, 2, 3]; test(a, b); console.log(a); console.log(b);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Con a = [1, 2, 3, 4]; está anulando el argumento (que es local para la función) que ha pasado a la test de función. No está realizando ningún cambio en la matriz real a . Ahora el interior a ni siquiera apunta a arreglo exterior.

Pero ocurre un cambio cuando haces b.push(4) , que en realidad muta la matriz b afuera.

 function test(a, b) { a = [1, 2, 3, 4]; b.push(4); } a = [1, 2, 3]; b = [1, 2, 3]; test(a, b); console.log(a); console.log(b);

about 4 years ago · Juan Pablo Isaza Report
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!