Тёмный

Hoisting in JavaScript and function scope issues with keyword var 

techsith
Подписаться 148 тыс.
Просмотров 64 тыс.
50% 1

Understanding Hoisting in JavaScript, also look at function scoping with keyword var.
In this tutorial we look at following issues with keyword var in ES5
- function scope issues
- Hoisting
- lack of const
Solution with keyword 'let' and 'const' in ES6 ( ES2015)

Наука

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

 

27 фев 2017

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 179   
@Sarmadfarhankhan
@Sarmadfarhankhan 7 лет назад
whenever I have doubts in JavaScript , I think of techsith 😉
@NishantGupta_Neo
@NishantGupta_Neo 6 лет назад
No one has explained Hoisting, let alone the reasons for hoisting in such a lucid manner !
@Techsithtube
@Techsithtube 6 лет назад
I hope it cleared the concept for you . Thanks for watching Nishant!
@NishantGupta_Neo
@NishantGupta_Neo 6 лет назад
techsith without a shadow of doubt!
@UrbanBDKNY
@UrbanBDKNY 7 лет назад
Thanks for the video. The best information I got from this video is that let is block scope. That goes a long way towards knowing how to use it and how it is different from var which is function scoped etc
@anacarolinamedeiroslabeca2761
@anacarolinamedeiroslabeca2761 7 лет назад
Very nice video. Finally understood the issues of using var and the advantage of using ECMAScript 6 'let' keyword instead. Thank you very much!
@Techsithtube
@Techsithtube 7 лет назад
Glad to know. Thanks for watching :)
@joshrochon6243
@joshrochon6243 6 лет назад
Wow, hilarious. When you brought up the thing about the interview. Had one today, they asked me about hoisting, and i didn't do so great, and now I'm here
@krishnat9767
@krishnat9767 5 лет назад
Excellent..simple and straightforward..
@subhashmahimaluri
@subhashmahimaluri 5 лет назад
You are very good teacher, explained with examples. I have learned lot of things from your tutorials.
@Carl-yu6uw
@Carl-yu6uw 5 лет назад
Mr T Sith, so clear, so useful, so thank you!
@justyna6134
@justyna6134 2 года назад
I like your style of explaining the issues - respect ! Thank you !!!
@vinodhpaul3870
@vinodhpaul3870 5 лет назад
I really love the way you explain the most confusing concepts in js...Feels like you have the right choice of words that trigger my brain to understand..lol. I will make sure to follow your vids regularly. Keep posting cheers!!!!
@gaurab1247
@gaurab1247 6 лет назад
Thanks for making ours life tremendously easy.I have been watching all of your's tutorials and you have a great teacher in you.Keep it up.It would be great if you come up with some DS/Algo tutorial as well.
@shyam123m
@shyam123m 5 лет назад
Simple and perfect explanation. Thanks Sir.
@himanshushah2683
@himanshushah2683 6 лет назад
The best explanation in all the tutorials video. not found better than your explain.keep posting, keep sharing .
@Techsithtube
@Techsithtube 6 лет назад
Thanks Himanshu for watching!
@arpitdubey17
@arpitdubey17 5 лет назад
i really appreciate your work....and your teaching skill are awesome....simple and easy to learn by you.....................thank you so much..........
@ahmedboutaraa8771
@ahmedboutaraa8771 4 года назад
your tutorials are art int itself
@mahesh82398
@mahesh82398 7 лет назад
Best clarification of let and const keywords, i have seen so far. Thanks Sir :)
@Techsithtube
@Techsithtube 7 лет назад
Thanks :)
@indrajitmate2904
@indrajitmate2904 6 лет назад
Best simple n most understandable concept .....
@piashmehedi
@piashmehedi 5 лет назад
techsith is simply best for javascipt :)
@edwinrodriguez9025
@edwinrodriguez9025 5 лет назад
great explanation about the scopes. Thanks
@vicentec1521
@vicentec1521 5 лет назад
Mozilla needs to hire you to simplify their documentation! Thank you very much!
@MajidEltayebZ
@MajidEltayebZ 4 года назад
Thanks for your simple explanation, this really means you understand what you're talking about, keep going (Y).
@xuelianwang5300
@xuelianwang5300 5 лет назад
Super Clear! Thank you!
@BigMoneySniper
@BigMoneySniper 6 лет назад
Your unbelievable man.... Straight up unbelievable. God has blessed us with hell of a JS Guru. I wont take this blessing for granted. Unbelievable should be your nickname brotha. Keep up the amazing work.
@Techsithtube
@Techsithtube 6 лет назад
Thank you for watching! :)
@shashankpandey1019
@shashankpandey1019 5 лет назад
Really a great tutorial , I have ever seen.
@damoon_az2465
@damoon_az2465 6 лет назад
Great explanations, your video made hoisting much easier to understand:)
@Techsithtube
@Techsithtube 6 лет назад
Thanks for watching! :)
@anishvijay6445
@anishvijay6445 2 года назад
I really enjoyed the video and understood all the concepts related hoisting and issues of constants
@mdawadud3520
@mdawadud3520 4 года назад
I really appreciate it because it is more clear than all video i get over the internet and please show us a complete video course about zero to advance level. thanks
@Techsithtube
@Techsithtube 4 года назад
Shiplu I have a full course here udemy.com/js-masterclass/
@hemantgajbe8366
@hemantgajbe8366 5 лет назад
Thank you Sir for clearing concepts !!
@mustaphag
@mustaphag 7 лет назад
Excellent Video. Keep up the good job
@anupsingh24
@anupsingh24 7 лет назад
Great video buddy, cleared my doubts.
@quarter-lifecrisis5127
@quarter-lifecrisis5127 3 года назад
so simple and informative ❤👍🏻 thank you
@dhilipkumar5867
@dhilipkumar5867 6 лет назад
Nice explanation..keep doing the good work
@souravsuman2633
@souravsuman2633 4 года назад
It was very helpful sir ....... explanation was clear and perfect....
@rakeshpatidar4426
@rakeshpatidar4426 6 лет назад
It's amazing, The way of representation is awesome.
@Techsithtube
@Techsithtube 6 лет назад
Thanks for watching ! :)
@prostoLelouch
@prostoLelouch 7 лет назад
Thanks for this tutorial! You did a great job!
@Techsithtube
@Techsithtube 7 лет назад
Thanks for watching!
@davitjanashia9344
@davitjanashia9344 3 года назад
Very clear and intelligent explanation! Thank you! 💡 👍🏻
@83manosar
@83manosar Год назад
yes bro
@vishnum9747
@vishnum9747 Год назад
Your videos are so informative keep uploading new videos
@pramodkumarw
@pramodkumarw 6 лет назад
Awesome example with simple explanation and presentation
@Techsithtube
@Techsithtube 6 лет назад
Thanks for watching Pramod!
@ankitkumarvashist8991
@ankitkumarvashist8991 5 лет назад
You are a great teacher , i have doubts even after watching other JS tutorial, as they teach the syntax only, not clarifying the doubts why we use any particular syntax what it does. #Love and Respect to you from INDIA.
@Techsithtube
@Techsithtube 5 лет назад
I am glad it helped. THanks for watching and keep learning!
@naren6666
@naren6666 7 лет назад
Awesome tutorials...
@vohoangan6121
@vohoangan6121 3 года назад
Well explain so easy to understand, thank you so much
@MylesGmail
@MylesGmail 5 лет назад
Awesome channel!
@TheSuyashgupta
@TheSuyashgupta 3 года назад
felt happy after seeing the video, doubt cleared
@catherinecordova512
@catherinecordova512 6 лет назад
This was so clear and helpful! Thank you!!!
@Techsithtube
@Techsithtube 6 лет назад
Thanks for watching Catherine! :)
@faisaltalukder5425
@faisaltalukder5425 Год назад
Effective Vedio for learning ✅
@sahilarora7186
@sahilarora7186 3 года назад
That was clean sir. Thank you
@AmeerHamza-jy5ml
@AmeerHamza-jy5ml 4 года назад
Thnaks Respected Sir 🤗 Lot of Love from PAK
@Techsithtube
@Techsithtube 4 года назад
Keep on learning brother and thanks for the kind comment.
@shikharchaudhary6984
@shikharchaudhary6984 4 года назад
Best explanation.
@AngeliqueGia
@AngeliqueGia 5 лет назад
Best tutorial! Thanks
@Techsithtube
@Techsithtube 5 лет назад
Thanks for watching Gia:)
@codeative
@codeative 5 лет назад
You're amazing .. thank you
@Paunitza
@Paunitza 3 года назад
Great explanation. Thank you!
@Techsithtube
@Techsithtube 3 года назад
Glad it was helpful! Thanks for watching!
@utkarshkandpal5960
@utkarshkandpal5960 6 лет назад
Your videos are Vader Level!
@Techsithtube
@Techsithtube 6 лет назад
the best way to explain the dark side of JavaScript :)
@higherpurpose1212
@higherpurpose1212 3 года назад
great explanation, thank you.
@Pm80334
@Pm80334 5 лет назад
Best in business , fantastic to say the least▶️
@Techsithtube
@Techsithtube 5 лет назад
Thanks Prasad for watching and an Awesome comment.
@mohamedelhousany4960
@mohamedelhousany4960 5 лет назад
you are good resource to learn js
@rohil3023
@rohil3023 4 года назад
This helped me understand hoisting thanks alot :)
@satyendrakannaujiya187
@satyendrakannaujiya187 5 лет назад
Thanks great tutorial
@heshankumarasinghe3159
@heshankumarasinghe3159 3 года назад
Thank you. This video has been really helpful. I learnt new things......
@Techsithtube
@Techsithtube 3 года назад
Glad it was helpful! Thanks for watching!
@shilpasyal55
@shilpasyal55 5 лет назад
Great Video. Thanks 😊
@vishalprajapti3544
@vishalprajapti3544 4 года назад
Very helpful tutorial....
@salmanmoin3588
@salmanmoin3588 5 лет назад
very nicely defined, pls keep on doing advanced JS topics incl arrow fn etc.
@Techsithtube
@Techsithtube 5 лет назад
salman , I have tones of topics on JS inducing arrow functions and advance JavaScript. please check it out. THanks for watching!
@Dipenparmar12
@Dipenparmar12 4 года назад
Great work... keep it up 💪😄😃
@Techsithtube
@Techsithtube 4 года назад
Thanks for watching buddy
@ganapathilana7069
@ganapathilana7069 2 года назад
clear example. thanks
@legendarygaming7790
@legendarygaming7790 3 года назад
Great Video.
@amanueltadesse1655
@amanueltadesse1655 5 лет назад
the best place to look things
@alinawaz4034
@alinawaz4034 5 лет назад
nice Explanation
@tranhuy2304
@tranhuy2304 6 лет назад
thank you for covering this, its really clear out everything i want to know. So near the end of the video when you declare the var y = 2 outside the function expression even though inside the function it already had the console.log for y before we initialize the y with 1 so thats when the hoisting kicked in rather than the lexicial scope rule where every outer environment can be accessed inside function so in this case the hoisting just declare the variable y and not initialize any value for the variable y so in this case undefined. So far i think javascript is the only language that one declare a variable in a global scope you can literally use it almost any where, javascript function is also an object itself. It would be nice to see you explain about the scope chain and closure🤔🤔But keep up the good work bro
@Techsithtube
@Techsithtube 6 лет назад
I do have a video on both scope chain and closures. you can check it out. Thanks for watching!
@kaushikdalvi4641
@kaushikdalvi4641 5 лет назад
Thank you so much!
@tathagata1000
@tathagata1000 4 года назад
Good one, thanks
@redeeshrv3319
@redeeshrv3319 6 лет назад
Superb !!! Please do some videos on JavaScript common patterns
@Techsithtube
@Techsithtube 6 лет назад
I do have plans for that. Will start making them soon.
@davideugene7911
@davideugene7911 6 лет назад
Merci beaucoup. C'était très clair :)
@Techsithtube
@Techsithtube 6 лет назад
Merci d'avoir regardé :)
@davideugene7911
@davideugene7911 6 лет назад
:) So you speak French?
@Techsithtube
@Techsithtube 6 лет назад
Little bit. Few years ago, I stayed in Paris for few months. That's when I learnt french.
@ashwinichougale3432
@ashwinichougale3432 3 года назад
Very nice video.
@Techsithtube
@Techsithtube 3 года назад
Thank you very much!
@iqraabdulrauf3402
@iqraabdulrauf3402 4 года назад
good one
@zaibkhan4862
@zaibkhan4862 6 лет назад
Really help me :) Thank you
@Techsithtube
@Techsithtube 6 лет назад
Thanks for watching :)
@gabovanlugo
@gabovanlugo 7 лет назад
Awesome!
@Techsithtube
@Techsithtube 7 лет назад
thanks for watching! :)
@ScienceExploration101
@ScienceExploration101 4 года назад
Ur the best
@Techsithtube
@Techsithtube 4 года назад
Thanks Ankit for a an awesome comment
@akshaysharma30498
@akshaysharma30498 5 лет назад
Who... Who... Would dislike this great video XD... The condition could be they didn't want to learn anything XD .... Great explanation as always!
@Techsithtube
@Techsithtube 5 лет назад
Thanks buddy. I appreciate the comment. Thanks for watching!
@yanivsalman9685
@yanivsalman9685 6 лет назад
this is the best video on that subject. i think you should do some udemy curses so you will se some money of your work!
@Techsithtube
@Techsithtube 6 лет назад
Thanks . I am thinking of building a udemy course.
@100krishna100
@100krishna100 6 лет назад
Thanks for the video. Can I know the difference between lexical scoping and function Closures?
@Techsithtube
@Techsithtube 6 лет назад
lexical scoping means variable defined outside the function is available inside. Function closure is , when a function uses a variable defined outside because of the lexical scoping, it will hold it inside a thing call closure ( internally) , so if you return this function it will persists the value where ever its used. I do have few tutorials on it. one is called closure, another is function chaining and there is also a tutorial on function mixins which uses closures.
@MahanteshGurav
@MahanteshGurav 5 лет назад
Thank you.
@amanansari5567
@amanansari5567 5 лет назад
great
@abhaysehgal5457
@abhaysehgal5457 7 лет назад
awesome video sir....just one advice i want to give you please put this video in top of this playlist...as i started watching your playlist and in above videos you have used "let" then for finding difference between var and let takes a lot of time...but after watching this video i get completely understand the difference between these two...once again thank you so much...waiting for more videos :)
@carlosw9379
@carlosw9379 5 лет назад
Thanks!
@manojkumarganigapeta2966
@manojkumarganigapeta2966 6 лет назад
nice video it's really helping to me thanks sir , have you done any video on design patterns in javascript sir?
@Techsithtube
@Techsithtube 6 лет назад
I am using design patterns in many places. Here are some of the videos. call, apply and bind: ru-vid.com?o=U&video_id=AYVYxezrMWA Decorator pattern: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-_8wOde1fmEM.html Factory Pattern: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-DpGuDFK4xss.html
@parasmaniseth7873
@parasmaniseth7873 3 года назад
Interviewer : do u watch techsith Me: yes Interviewer : you are hired
@Techsithtube
@Techsithtube 3 года назад
I hope that did really happened :)
@parasmaniseth7873
@parasmaniseth7873 3 года назад
I have mentioned ur channel in the interview and got to know that interviewer also follows u🤪
@deeproy7292
@deeproy7292 5 лет назад
thank you
@prakharmathur8431
@prakharmathur8431 6 лет назад
good job bro
@Techsithtube
@Techsithtube 6 лет назад
Thanks for watching prakhar.
@akbaralimajeed
@akbaralimajeed 5 лет назад
Nailed it
@neilpearce
@neilpearce 6 лет назад
It's during the execution context, the JS engine will store all variable and function declarations in memory. Every function creates its own execution context and memory bank. That's why you can call/evoke a function before it is defined, because that declaration has already been stored. ;-)
@Techsithtube
@Techsithtube 6 лет назад
yes, perfectly explained. :)
@specsbattle1340
@specsbattle1340 5 лет назад
Yep this was in my interview today lol.
@Techsithtube
@Techsithtube 5 лет назад
Hope you answered it correctly. . :)
@specsbattle1340
@specsbattle1340 5 лет назад
@@Techsithtube not quiet, I was not too clear about the var behavior in functional scope vs block scope. Now I am much more clear on this topic thanks to you. I also watched and liked your setTimeout with var and let, that was the exact question she asked. I am also making videos on my channel about tech interviews, I think the best way to learn is to teach. Now I am more confident to go to any UI interviews because as far as I know, scope questions always come up and now I should able to explain the weird behavior of var.
@jacksto123
@jacksto123 4 года назад
Thanks for the video. Is var still used often? Or is everyone using let and const now?
@Techsithtube
@Techsithtube 4 года назад
I think you should only use let and const. now that most browsers supports it.
@Nonsequitor415
@Nonsequitor415 5 лет назад
thanks
@woofwoofunited
@woofwoofunited 5 лет назад
Well explained, thank you. Is there ever a usecase where you would rather use var instead of let?
@Techsithtube
@Techsithtube 5 лет назад
You should not use 'var' at all . its anipattern.
@woofwoofunited
@woofwoofunited 5 лет назад
Thanks I use const or let instead, from experience though has there been a usecase where var is preferred to let. Im assuming no?
@Techsithtube
@Techsithtube 5 лет назад
yes use let or const , and never use var.
@woofwoofunited
@woofwoofunited 5 лет назад
Thank you, well done on making such a good video!
@Tofurskii
@Tofurskii 2 года назад
good
@chirashankar4495
@chirashankar4495 3 года назад
Can you please explain the second part where you assign 2 to var y and then if you comment out the other assignment to the same variable the console.log would display 2.
@rajashekhar433
@rajashekhar433 3 года назад
Looking for more videos on cloud
@swathikumar3074
@swathikumar3074 4 года назад
whenever create any variable with var keyword it will be added to window (dom) object directly so it will be available in that particular context var is like global variable. var v; console.log(window.v);-->u will get undefined not an error
@customdev7078
@customdev7078 5 лет назад
hey..@techsith what are uses of varaible hoasiting ..
@Techsithtube
@Techsithtube 5 лет назад
There is no use of variable hoisting its one of the side effect of functional scope .
@nobir98
@nobir98 2 года назад
I think 'let' do hoisting but it doesn't assign to default value undefined. it assign where the developer declared. I might be wrong though
@volodymyrkhimiak1460
@volodymyrkhimiak1460 6 лет назад
ДЯКУЮ!!! It is "Thank you" in Ukrainian!
@Techsithtube
@Techsithtube 6 лет назад
धन्यवाद in hindi. Thanks for watching!
Далее
Async Await JavaScript ES7
26:39
Просмотров 120 тыс.
Tricky JavaScript Interview Questions and Answers
16:35
Differences Between Var, Let, and Const
8:37
Просмотров 181 тыс.
setTimeout and setInterval in JavaScript
12:55
Просмотров 34 тыс.
JavaScript Functions Crash Course
1:36:54
Просмотров 154 тыс.
Tricky JavaScript interview questions and answers
21:01
How To Unlock Your iphone With Your Voice
0:34
Просмотров 25 млн