79557871

Date: 2025-04-06 06:45:26
Score: 0.5
Natty:
Report link
  1. Use let (or const) by default: They behave more predictably and reduce subtle bugs due to scoping issues.
  2. Avoid var in modern JavaScript: There's rarely a good reason to use it anymore unless you're maintaining legacy code.
  3. Readability & Safety: let makes block scope explicit, which improves code clarity, especially in loops and conditional blocks.

When might var still appear?

  1. Legacy codebases: You'll often see var in older projects or tutorials.
  2. Global variables workarounds: var declared in the global scope becomes a property of the global object (window in browsers), which can come in handy in a couple of situations).

Random use case:

<script> 
 var title = "Glamorous title"
</script>

Use title in other locations. In modern language this can done in other ways, for sure more elegant. Always take in account risky side effects.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: razvanmoga