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

127
Vistas
Javascript beginner - function modifiing global const

I'm currently learning js and stumbled upon this to me weird behavior. I probably missing something fundamental here, but i can't find the answer.

I have a function that modifies an array and returns it. If i print that out the original array gets modified, even though it's a constant.

const arr = [5, 9, 7, 1, 8, ];

function test(arr) {
  const strings = ['qwe', 'asd'];
  arr.splice(1, 0, ...strings);
  return arr
}

console.log(test(arr))
console.log(arr)
console.log(test(arr))
console.log(arr)
console.log(test(arr))
console.log(arr)

Output shows that the original array gets bigger everytime. I was expecting that it is the same output everytime.

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

0

A const means you cannot reassign to it like this

const arr = [1, 2, 3];
arr = [5, 4]; // You cannot do this that's const

other than that you can modify the array contents

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