DEV Community

Boots
Boots

Posted on

When is the last time you used `var`?

I used var last week, and it made me nostalgic.

I feel kinda bad for var. Sometimes I get the feeling we live in a strictly let and const world these days.

Tell me about the last time you declared a variable with var. What music were you listening to? What was the codebase like? Was it the 90s????

Latest comments (18)

Collapse
 
lehmannsystems profile image
Mike

Today :'( Legacyyyyy code

Collapse
 
ccleary00 profile image
Corey Cleary

I haven't used it in forever. 95% of the time now I use const. By making a concerted effort to avoid using let and the mutability it allows (not that const is truly immutable), it has made the code I write much, much cleaner and easier to reason about.

Collapse
 
moopet profile image
Ben Sinclair

Yesterday. It'll probably be today, too, but it was definitely yesterday.

Collapse
 
diek profile image
diek

My last time was some years ago xD i don't even remember the last time i used it.

Collapse
 
mzaini30 profile image
Zen

I don't use this yet 😂

Include let and const. Because, I write like this is run:

name = "Zen"
Collapse
 
nombrekeff profile image
Keff

I think I haven't used it in years, except in DevTools. Though this is no longer needed with Chrome 80, which allows redefining let.

I was listing to Mozart playing live If I recall correctly. Just kidding, I don't remember exactly when I used it last

I have never looked back, not one single time.

Collapse
 
daniel13rady profile image
Daniel Brady • Edited

The last time I used var was the last time I worked in a JavaScript code base in which I was the only contributor: anytime I try to use it in public, I get shot down by humans or an opinionated linter, or both 😞.

Ideally, I would use it more often. It's not a replacement for let or const, just like they aren't drop-in replacements for var or each other. I actually wrote about how I would prefer to use it here:

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

In the console all the time.

Collapse
 
mzaini30 profile image
Zen

Wow

Collapse
 
daniel13rady profile image
Daniel Brady

Haha if I'm in a console, I don't care about binding semantics and so I usually don't use a declarator at all! A simple x = 42 is sufficient, in that context.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

For me it's just a good habit

Collapse
 
mzaini30 profile image
Zen

I'm too 😂

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

So Python.

Collapse
 
brettimus profile image
Boots

same here! it feels so freeing. like running through a field

Collapse
 
nombrekeff profile image
Keff

Definitely, same here, though it seems chrome 80 has added the ability to redefine let variables

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Good to know, is this only in console or has spec chqnged

Thread Thread
 
nombrekeff profile image
Keff

I think it's just in the console, they also allow class to be redefined. You can check the release notes if you're interested in learning more: developers.google.com/web/updates/...

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Every time I risk polluting global scope including,

  • Chrome DevTools (Inspect Element)
  • Top level scripting in <script></script> tag.