The Best Way to Declare Variables in JavaScript?

preview_player
Показать описание
In today's video, I'll take you through 3 similar code examples in JavaScript, giving us 3 totally different outcomes. The intention of this exercise is to demonstrate the differences between const, let, and var in JavaScript.

Moral of the story: use 'const' and 'let' where possible 🙂

For your reference, check this out:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

Dcode you are the best! Everytime i get into a new topic in JS i ALWAYS look for your channel first to check if you have made a video about it, you are a life savior, thank you!

It_guy
Автор

I hope this gets the 1 million views it deserves! let and const are always explained in way (for me) that are overly complicated. While these concepts are some level of complex, your explanation was 😮😮😮 ❤ #thankYou3000

edutainment
Автор

Myself being late to the JS game, tbh I never use var - and find myself leveraging both const and let through all my work. There's probably a random use case out there that exists for var, but I'm yet to find it.

karlstenator
Автор

Not really mind boggling but I guess it depends on how you learn. Scopes and hoisting were one of the first things I've learned when I started programming (which also was in Javascript), after the complete basics such as what's a variable, function, etc. of course. I've always used const and let exclusively and understood what's going on in the scopes, including the scopes that have var e.g. in some existing code.

Whenever I see "var" used it's always a) old code, b) people who're learning and don't quite understand the concept, or c) people who've come from a different language and try to do things in Javascript the same way they would in the other language.

The C group is actually very similar to when people learning a human language rely on translating things from their native language too much. Their grammar, word order, etc. is always off because they're basically relying on these fixed rules from their own language and try to replicate it word-for-word in the language they're learning (it never goes well).

Gigusx
Автор

im new to channel your videos about js really cool !! keep it !! im learning Js i want to be really good any tips or advice ?

amoh
Автор

I think we should forget that var exist, I haven't used it for years.

DK-pfdg