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

195
Views
Creando un objeto 'const const' en javascript

En javascript, si creo una matriz const, aún puedo modificar el objeto al que apunta la variable:

 // The const declaration creates a read-only reference to a value. // It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const const x = [1,2,3]; x.push(4); console.log(x); x=55 // But this is illegal and will error console.log(x);

¿Hay alguna manera de hacer que los elementos de una matriz también sean inmutables? Similar a algo como const int* const x; ¿Cía?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar Object.freeze para evitar que se cambie un objeto (o una matriz):

 const x = [1, 2, 3]; Object.freeze(x); x.push(4); // This will throw an exception
about 4 years ago · Juan Pablo Isaza Report

0

los objetos congelados con Object.freeze() se vuelven inmutables.

Aquí están los documentos: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze

Ejemplo:

 const x = [1,2,3]; Object.freeze(x);
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!