0

Is there any difference between javascript's let, var, and const in terms of memory management and performance?

Keeping aside the major difference that const variables can't be reassigned a value, does using const actually save memory compared to let or var (such as javascript would assign exactly the needed amount of memory to store the value?)

Lorraine R.
  • 1,545
  • 1
  • 14
  • 39
  • They do slightly different things so they get compiled and optimised slightly differently, but these differences are so small that they should not affect your decision when to use which. – Bergi Dec 26 '21 at 22:43
  • I'm building a really large-scale project, and processing a lot of data... So I'm looking for ways to optimize the code when this is possible. – Lorraine R. Dec 26 '21 at 22:48
  • 3
    This is not a way. Choose the declaration (`let` or `const`) to benefit the code readability for developers, in large-scale projects improved maintainability is a much larger optimisation factor than twiddling with memory. – Bergi Dec 26 '21 at 22:54
  • 1
    Also, the rule of thumb for optimising javascript performance is to write idiomatic code - as that is what engines aim for to optimise best. – Bergi Dec 26 '21 at 22:55

0 Answers0