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

156
Vistas
Can I use const to assign jQuery or should I use let?

When I save a jQuery result to a variable so that I can reuse it later, can I declare that variable const? Or is there something about the internal workings of jQuery that makes it better for me to use let?

const $myDiv = $("#myDiv"); // will I be sorry later that I used const instead of let?
$myDiv.doThing1();
$myDiv.doThing2();
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Using const is perfectly acceptable. The main reason you'd use let instead would be if you wanted to reassign $myDiv, something like:

let $myDiv = $("#myDiv"); // will I be sorry later that I used const instead of let?
$myDiv.doThing1();

$myDiv = $("#myOtherDiv") // this will break at you if $myDiv is a const
$myDiv.doThing2();

When $myDiv is a const, it doesn't prevent you from mutating it, just from reassigning it.

about 4 years ago · Juan Pablo Isaza Denunciar

0

This really only comes down to whether or not you intend to store other information to $myDiv.

If not, then continue to use const. If yes, you should use let.

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