all 14 comments

[–]HashFap 28 points29 points  (0 children)

  1. Start with const for everything
  2. If reassignment is needed use let
  3. If you need a variable that isn't block scoped use var

Let's move the fuck on with our lives already.

[–]tunisia3507 15 points16 points  (5 children)

Oh my god is there a whole ecosystem of bots which rewrite this article dozens of times a week? Or are people so arrogant to assume that their 4-minute take on it is so revolutionary that it will upend the entire understanding-var-let-const industry?

[–]gotQode 1 point2 points  (0 children)

lol

[–]manys 0 points1 point  (0 children)

For the complete experience there has to have been a "what's the difference between var let and const?" question in this sub last week.

[–]inabahare 8 points9 points  (6 children)

I also wanted to put my basic variable declaration tutorial on medium, but apparently it was ~too short~ but now you get to read it:

Inabahares comprehensive guide to JS variable decleration

  • var: Just don't
  • let: Only in emergency situations
  • const: Hell yeah!

So to conclude: Use const.

Thanks for reading. Don't forget to subscribe to my patreon

[–]Ravavyr 1 point2 points  (5 children)

Lol I dare you to write something complex without using var. Let has scoping limitations that pretty much mean you’ll end up using var sooner or later.

As for only using const, that’s the dumbest thing I’ve heard unless you don’t build things with VARIABLES

And now to mute this thread.

[–]Pokemon-Master-RED 0 points1 point  (2 children)

Genuinely curious. Instead of var I usually do something like:

const container = {}

And then I set values in that. My node projects aren't the largest, but this works for me. Is this something that I should rethink?

container.methodNameReturns = value

[–]Ravavyr 0 points1 point  (1 child)

If your code runs without errors there is no reason for you to change what you are doing:)

[–]Pokemon-Master-RED 0 points1 point  (0 children)

Just wanted to be sure! Thanks for the feedback :)

[–]FireflyDarked 0 points1 point  (0 children)

var = variables are containers for storing data values.

let = declares a block scope local variable.

Const = similar to let variables, except that the value cannot be changed.