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

158
Views
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 answers
Answer question

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 Report

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 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!