DEV Community

Discussion on: Let's Count Some Sheep!

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

I normally wouldn't make this kinda pedantic observation, but since you say you're "only 4 weeks into studies"...

Get rid of the var. You don't want to use that in "modern" JavaScript design. You should always, always, always use let or const.

It may feel right now like that's a semantic, rather useless, observation. But it's not just based on coding dogma. JavaScript has some particular, umm... headaches regarding this and the hoisting of var-declared variables into global scope. These headaches are solved by religiously sticking with let or constant.

The full description of why var is "problematic" is far longer than I care to type in this reply. But as you get further down your studies, it's a good thing to research.

Also, FWIW, the var keyword tends to cause headaches in other languages as well (e.g., C#).