Тёмный

When to use which (and how they differ). 

Academind
Подписаться 918 тыс.
Просмотров 18 тыс.
50% 1

var, let and const can be used to create variables in JavaScript. But when should you use which? How do they differ?
Join the full "Accelerated JS Training" course at: acad.link/js
Exclusive discount also available for my "Accelerated ES6 Training" course: acad.link/es6
Also check the "Primitive vs Reference Types" article + video: academind.com/...
Check out all our other courses: academind.com/...
----------
• Go to www.academind.com and subscribe to our newsletter to stay updated and to get exclusive content & discounts
• Follow @maxedapps and @academind_real on Twitter
• Follow @academind_real on Instagram: / academind_real
• Join our Facebook community on / academindchannel
See you in the videos!
----------
Academind is your source for online education in the areas of web development, frontend web development, backend web development, programming, coding and data science! No matter if you are looking for a tutorial, a course, a crash course, an introduction, an online tutorial or any related video, we try our best to offer you the content you are looking for. Our topics include Angular, React, Vue, Html, CSS, JavaScript, TypeScript, Redux, Nuxt.js, RxJs, Bootstrap, Laravel, Node.js, Progressive Web Apps (PWA), Ionic, React Native, Regular Expressions (RegEx), Stencil, Power BI, Amazon Web Services (AWS), Firebase or other topics, make sure to have a look at this channel or at academind.com to find the learning resource of your choice!

Опубликовано:

 

13 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 45   
@MattH479
@MattH479 5 лет назад
Teach me, Sensei! Another very informative lesson. Thanks for such invaluable, free, content!
@academind
@academind 5 лет назад
Thanks Matt!
@GhulamMustafa-cf2nk
@GhulamMustafa-cf2nk 5 лет назад
Please make full course video like this on JavaScript so that we can understand as in this video that is super master and clean way to explain what actually happening in code that we write.
@9SMTM6
@9SMTM6 5 лет назад
Btw, there's also a 4th type of getting a variable, which is using an undeclared variable, which will then be a global variable.
@rahultripathi8865
@rahultripathi8865 3 года назад
Video is very informative, But I would suggest to use any other IDE instead of codepen to explain even simpler things.
@rvuyyuru
@rvuyyuru 5 лет назад
What is Closure in JavaScript ? Please explain max ... Thanks in advance
@academind
@academind 5 лет назад
I think it's worth a separate video. A bit too complex to squeeze it into this one but definitely something I wanna cover in a new video.
@akn9699
@akn9699 5 лет назад
Purchase the Book "Speaking JavaScript". Follow along that and your doubts will be clear. BTW, It is the best book for JavaScript.
@rvuyyuru
@rvuyyuru 5 лет назад
@@akn9699 thanks
@willigeek2013
@willigeek2013 5 лет назад
Hi Max, just saying ... i love your course. I'm currently taking the Angular complete guide course. But i would like to know how you could approach making a carousel component with Angular Material. That would be very helpful. Thank you
@9SMTM6
@9SMTM6 5 лет назад
My recommendation: ``` try{ usingConst(); } catch (assignmentError) { try { rewritingToBeAbleToUseConst() } catch(itsLessElegantThanJustUsingLet) { useLet() } } ``` Or in normal words: Always use const, unless you find out that you can't (well my IDE does that for me), then think if you can not do it without reassigning, and if you find out that reassigning is the most elegant solution use let. Never use var if you want behavior as seen in other programming languages. In my projects large enough to justify a linter, its actually set to forbid var, and warn about using let to define a variable that's not reassigned. In these projects I'd say that I use const variables ~95% of the time, well, when excluding function parameters that is.
@rohitchapagain348
@rohitchapagain348 5 лет назад
i think it is better to use document.write() than the console.log(). for the output function
@kerryd2060
@kerryd2060 5 лет назад
My favorite Udemy instructor!!
@academind
@academind 5 лет назад
Thank you Kerry :)
@adrianoalves-qripto
@adrianoalves-qripto 5 лет назад
Thank you for sharing, Max!
@academind
@academind 5 лет назад
Thank YOU for your comment Adriano!
@LosEagle
@LosEagle 5 лет назад
Please consider making Udemy course on Elm. Elm has very little video courses and tutorials so anyone learning it has mostly to rely on official guide which is a shame because it's very interesting take on functional programming. If not Elm then at least Reason maybe? Both are very relevant to the technologies you are normally teaching and both have decent fanbase around them so it would help Academind grow.
@skeepskeeperson
@skeepskeeperson 5 лет назад
Some slight issues with "let" and IE 11 mentioned on Can I Use. So if you have to support IE11 in the real world, just be aware of some potential problems.
@raymondwaluyo4082
@raymondwaluyo4082 5 лет назад
Hi max, love your videos. Can you do videos about socket.io with node and perhaps do some notification or messaging on react. I always like your videos better than other tutorial videos on the internet. Im thinking to play a bit with socket io and perhaps build some cool stuff but the docs on socket io is rather minimal.
@academind
@academind 5 лет назад
Thank you Raymond. Got no plans regarding socket.io at the moment to be honest but we'll see.
@Martin-4D
@Martin-4D 5 лет назад
let in the for loop blew my tiny mind
@shashigupta5206
@shashigupta5206 5 лет назад
Keep doing great work. And I have learnt a lot from your videos here and on udemy as well. Big fan Thanks :)
@academind
@academind 5 лет назад
Thanks a lot for your support Shashi, I'll do my best to keep it up :)
@willysnowman
@willysnowman 4 года назад
Thank You!!
@farhantariq8401
@farhantariq8401 5 лет назад
@Academind can you please create a series on websockets...
@academind
@academind 5 лет назад
No plans regarding that at the moment, sorry Farhan.
@farhantariq8401
@farhantariq8401 5 лет назад
@@academind No Problem. Thanks
@Dev-ry9cx
@Dev-ry9cx 5 лет назад
I am planning to make some soon!
@drjones694
@drjones694 4 года назад
Thank you
@omprakash5294
@omprakash5294 5 лет назад
I'm beginner which one learn first flutter or react native
@academind
@academind 5 лет назад
Please have a look at this video => academind.com/learn/flutter/react-native-vs-flutter-vs-ionic-vs-nativescript-vs-pwa/
@christos.dimitroulis
@christos.dimitroulis 5 лет назад
I remember this one is this from a course ?
@academind
@academind 5 лет назад
It is not. I recorded this video yesterday, it's not part of any course.
@aryanshmahato
@aryanshmahato 5 лет назад
Sir your courses on Udemy are great.
@academind
@academind 5 лет назад
Thank you for this great feedback Aryansh!
@Netrole
@Netrole 5 лет назад
Honetly the only time the blockscoping of let is annoing is in cases like this: try{ let res = getResource() }catch(e){} useResource(res) this does not work with let, but works just fine with var.
@9SMTM6
@9SMTM6 5 лет назад
Uhm... If that would work it would defeat the very purpose of let. What you want to do is simply declaring outside of the catch block: ```js let result; try{ result = canFail(); } catch(exception) { console.error('encountered', exception, ' using fallback function cantFail that's somehow worse but will succeed'); result = cantFail(); } const endResult = doSomethingWith(result); ```
@Netrole
@Netrole 5 лет назад
@@9SMTM6 I know that... I just said this is the only case where i prefer the way var works over let. I just don't like declaring variables upfront.
@9SMTM6
@9SMTM6 5 лет назад
@@Netrole Hmm yeah I also don't like having predeclared variables. But I barely ever have to use them, and I don't have to drop back to var either. I.e. in this situation I'd probably just pack the whole try-catch block in a function, with changing variable assignment to return, and in the end assign the result of the function call to a const.
@trendingamvanimemoviesgame140
@trendingamvanimemoviesgame140 5 лет назад
Brother I am using an api in react native can you help me with that?
@Yagamilight19383
@Yagamilight19383 5 лет назад
Yes they do sound cooler 😂😂
@Capatron1
@Capatron1 5 лет назад
Great video, but it could be way shorter! Half of it just explains the scope of variables and not the actual title. I acknowledge one needs some context, but this one takes half the video and does not explain important topics like variable hoisting, strict mode or variable shadowing
@KayahanKahrman
@KayahanKahrman 5 лет назад
I think video length is ok. We'r not javascript experts, just trying to learn it from scratch. Explaining concepts like this really helps a lot.
@Dev-ry9cx
@Dev-ry9cx 5 лет назад
Hey, I made the same video and I have some similar thoughts
@MeAsMeButMe
@MeAsMeButMe 4 года назад
Kinda awkward giving the 666th like while there are also 6 dislikes! D: haha Great video though, so it's worth it! xD
Далее
Сколько стоят роды мечты?
00:59
Просмотров 339 тыс.
Батя всех бургеров на 7000 ккал!
00:55
Differences Between Var, Let, and Const
8:37
Просмотров 188 тыс.
The Most Important Skill You Never Learned
34:56
Просмотров 202 тыс.
Making Sense of the Tricky Parts of JavaScript
31:12
Просмотров 51 тыс.
SQL vs NoSQL or MySQL vs MongoDB
21:30
Просмотров 1,8 млн
Why Signals Are Better Than React Hooks
16:30
Просмотров 475 тыс.
Sending JavaScript Http Requests with the fetch() API
16:50
How NextJS REALLY Works
28:25
Просмотров 147 тыс.
The JavaScript Survival Guide
14:47
Просмотров 727 тыс.
You might not need useEffect() ...
21:45
Просмотров 159 тыс.