JavaScript 'var' Usage

The cluster debates avoiding the 'var' keyword in JavaScript, promoting immutable constants with descriptive names since variables rarely vary, with irony noted in examples simulating variables.

➡️ Stable 0.5x Programming Languages
3,615
Comments
20
Years Active
5
Top Authors
#851
Topic ID

Activity Over Time

2007
7
2008
31
2009
47
2010
93
2011
115
2012
155
2013
184
2014
181
2015
210
2016
234
2017
229
2018
191
2019
187
2020
268
2021
298
2022
323
2023
307
2024
231
2025
308
2026
16

Keywords

e.g NF gv.el SQL JS NEWS ISTR ASCII JavaScript GDP variables variable var lexical names value code dynamic constants definition

Sample Comments

mavhc • Oct 31, 2025 • View on HN

Really should invent a new name if you don't want your variables to vary

asplake • Sep 4, 2022 • View on HN

Slightly ironic that it says you don't need variables, then in the example (and without comment) simulates one

pekk • Dec 18, 2014 • View on HN

More like "if the person who wrote this code didn't want to use the var keyword"

mcraiha • Oct 14, 2019 • View on HN

There should be a law that says: "one shall not use var in JavaScript code examples"

whipoodle • Aug 3, 2017 • View on HN

They're not variables if they don't vary ;)

abigail95 • Jan 24, 2024 • View on HN

i do the same because i find the var keyword ugly

seanwilson • Jun 18, 2015 • View on HN

What's wrong with introducing an extra variable compared to introducing a comment?

jerrre • Apr 3, 2018 • View on HN

const var would become a nice contradiction...

vidarh • Jan 24, 2013 • View on HN

That's.... creative... I particularly love how the variable names keep changing in inconsistent ways, but also sometimes reuse older names.

JulianMorrison • Feb 4, 2022 • View on HN

Fair point. "value" and "var" then, perhaps?