Learn JavaScript Scoping In 10 Minutes

  Рет қаралды 58,502

Web Dev Simplified

Web Dev Simplified

Күн бұрын

One of the biggest mistakes JavaScript developers make is not fully understanding how scoping works. There are 4 different levels of scoping and if you don’t have a strong grasp of how they interact with each other it can be incredibly difficult to write complex JavaScript code. In this video I cover all 4 different levels of scoping in JavaScript and how you can use them to your advantage.
📚 Materials/References:
ES Modules Video: • JavaScript ES6 Modules
ES Modules Article: blog.webdevsimplified.com/202...
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
⏱️ Timestamps:
00:00 - Introduction
00:30 - What is a scope
02:12 - Global Scope
04:02 - Module Scope
05:53 - Block Scope
07:35 - Function Scope
08:55 - Using multiple variables with the same name
#Scoping #WDS #JavaScript

Пікірлер: 73
@njayman
@njayman Жыл бұрын
I started learning web development somewhere near 2019. I was still in my undergrad and learning from you. I also used to follow dev Ed, Traversy media, New Boston, Fireship and Net ninja. I have finally landed a job as a JavaScript developer and it's all thanks to you guys. I learn something new every time I watch your videos.
@usua1myanmarian
@usua1myanmarian Жыл бұрын
Way to go man.
@emmm_4465
@emmm_4465 Жыл бұрын
Congratulations!
@dimitargetsov9690
@dimitargetsov9690 Жыл бұрын
@najish mahmud.With my full respect to You and to the authors listed above: please , edit Traverse to Traversy.Brad Traversy deservs it.
@DavidTheITGuy.
@DavidTheITGuy. 5 ай бұрын
How did you easily step in to use javascript basics into projects, it's hard for me here?.
@ori9390
@ori9390 Жыл бұрын
This is one of the best channels for those who want to learn the Web Development. Thanks for your efforts, Kyle!
@larrylam2914
@larrylam2914 Жыл бұрын
love this type of videos!! they are so informative while the topics may seem easy or general, but i learn things I didn't know every time
@daedalus5070
@daedalus5070 Жыл бұрын
Great one-stop video on scope. Wrote something the other day and scope was the only thing wrong with any of it!
@luisaborba4829
@luisaborba4829 2 ай бұрын
OMG you're video made so much more sense than the way my teacher was explaining scope to us at the bootcamp. Thank you so much Kyle!!
@lutho600
@lutho600 Жыл бұрын
Congratulations 🎊 man i didn't know you have more than 1 million subscribers. Your channel is very helpful, love from South Africa 🇿🇦
@gabrielv1856
@gabrielv1856 Жыл бұрын
Hello Kyle, first and foremost, thanks a lot for simplifying things a lot with your tutorials and lessons. I cant recall for how long ive been watching your channel but its been a while... (times goes really fast man...) I am currently working on a personal project that driving me to scope hell. The thing is that certain parts of the code (not just variables and functions) must me accessible by other parts of the code but some shouldnt and thus causing a headache were to place the scope of what. Another problem is that i know that by now there are a "managable" amount of code i can handle but it will become a monster with all the different parts of the project
@Juzzyjuzzy
@Juzzyjuzzy Жыл бұрын
Great explanation. Thanks for the illustration.
@raymondbyczko
@raymondbyczko Жыл бұрын
'let' is my friend. 'var' is subject to hoisting in the function context, which makes things messy I would think. Good work as always Kyle!
@SchnippSchnappShnappi
@SchnippSchnappShnappi Жыл бұрын
Thank you I finally fully understood!
@AcrylicHorizonsAbstractArt
@AcrylicHorizonsAbstractArt Жыл бұрын
Great explanations for how scoping works! However I'd be hesitant to say you *should* be using module scoping. There are definitely use cases where it's beneficial, but for example I have applications where a lot of variables and data need to be accessible to other scripts running (tracking, analytics, etc) and module scoping would make that more of a pain, so we have a lot scoped globally. Either way, great video with great information!
@BalaSubramanian-fl1fl
@BalaSubramanian-fl1fl Ай бұрын
Amazing Explanation
@carafachera4781
@carafachera4781 Жыл бұрын
Thank you Kyle !!
@lakhveerchahal
@lakhveerchahal Жыл бұрын
Thank you Kyle
@ara-ara845
@ara-ara845 Ай бұрын
well explained thanks alot... God bless
@Arabian_Epileptic
@Arabian_Epileptic Жыл бұрын
Thanks Kyle 💯
@valeriousmonk654
@valeriousmonk654 Жыл бұрын
Thank you!
@ythshhshsbsnshegebwnebeben2142
@ythshhshsbsnshegebwnebeben2142 Жыл бұрын
I know you mainly teach programming and best practices but i would really like to see a video about quickly designing restapis, documentations and databases from you. I know about openapi and a few gui editors and generators but it seems there are nearly no videos about the topic. If you need to designe a prototype backend with a hand full of schemas, yould you start in a Texteditor/IDE or would you choose a more or less automated process in which you define a schema once and use it to generate api, db and doc parts? If there is already a video from you about this topic i apologize, thx for reading and keep up the good work.
@NedumEze
@NedumEze Жыл бұрын
Kyle is a born Teacher. Thanks, Bud
@DavidTheITGuy.
@DavidTheITGuy. 5 ай бұрын
Your passion is teaching code bro
@masonnash9396
@masonnash9396 Жыл бұрын
Thanks Kyle!
@MinistryofJavaScript
@MinistryofJavaScript Жыл бұрын
Great share as usual.
@busyrand
@busyrand Жыл бұрын
Agreed. He's amazing.
@wpxpert98
@wpxpert98 Жыл бұрын
Thank you Kyler
@Peywan
@Peywan Ай бұрын
thank you!
@canerucar34
@canerucar34 Жыл бұрын
thanks for videos
@sowjanyasiddamshetty1532
@sowjanyasiddamshetty1532 Жыл бұрын
Hi Kyle, could you please do a video on decorators in javascript?
@tejibel2800
@tejibel2800 Жыл бұрын
Hey Kyle, i'm returning to writing typescript after almost a decade. I love your videos! Great use of clean code. I see you barely use semi-colons. Could you explain or maybe make a short on when to use them? Keep up making the great content.
@JunGull
@JunGull Жыл бұрын
JS doesn't require semi-colons. As far as I know, it automatically places then when it's parsed. It's pretty much up to you if you want to add them manually or not.
@tejibel2800
@tejibel2800 Жыл бұрын
@@JunGull Thanks for the response. I didn't think it was just a style choice! I'll just assume that for now. If i ever find an exception i'll return here to share so.
@navidghasemi9685
@navidghasemi9685 Жыл бұрын
@@tejibel2800 they are not just style choices! sometimes you need them to avoid misunderstanding js
@hypernylium9782
@hypernylium9782 Жыл бұрын
now, i know you are more of a javascript guy but hear me out. can you try to make a file uploader using html, css, javascript and php with a loading bar? btw love you content. watch all of you're videos 😅
@adebayoomolumo1938
@adebayoomolumo1938 Жыл бұрын
Congratulations on 1million
@emanuelecampora1999
@emanuelecampora1999 Жыл бұрын
Can you make a video about promise scope?
@kastussha1418
@kastussha1418 Жыл бұрын
You've got 1million!!!
@parekhnirajj123
@parekhnirajj123 Жыл бұрын
Plz make a video on class constructor and methods in js
@Fralleee
@Fralleee Жыл бұрын
I was expecting some mentions about lexical scope and closures.
@sureshanandsekar4384
@sureshanandsekar4384 6 ай бұрын
In React projects , we actually added the type:"module" in package.json . we dont add it manually as far as i knew in react js projects. correct me i am wrong folks.
@aalaeytb
@aalaeytb Жыл бұрын
helpful😍
@js-dev8682
@js-dev8682 Жыл бұрын
const and let use block scope while var use function scope
@HawkMcDork
@HawkMcDork Жыл бұрын
cool, my question is, if i create (or change) a variable inside of a function and want to use that new variable OUTSIDE of the function, how do i do that?
@mushfiqaraf5079
@mushfiqaraf5079 Жыл бұрын
Can you post a video on "Glass website" tutorial with CSS? 🤐
@InezhInezh
@InezhInezh Жыл бұрын
Best 🙂
@scienceandtechnology9379
@scienceandtechnology9379 Жыл бұрын
How can I recall a variable outside of the function scope?
@saurabhs4743
@saurabhs4743 Жыл бұрын
Bro also create videos on source control in vs code
@99baddar
@99baddar Жыл бұрын
Can you create a video or series of video for mern app with docker
@thatsawesome.
@thatsawesome. Жыл бұрын
YESSIR!
@deatho0ne587
@deatho0ne587 Жыл бұрын
Things like TSlint normally throw Warnings in the case of multiple variables with the same name in the same file, due to it is a bad practice.
@Harish-rz4gv
@Harish-rz4gv Жыл бұрын
Do javascript have statistics module?
@alwysrite
@alwysrite Жыл бұрын
if I create a js file, how do I know if it is module scope or not?
@ashkanahmadi
@ashkanahmadi Жыл бұрын
It's never a module unless you specifically specify type="module"
@jesusmanueldelvallepedros2608
@jesusmanueldelvallepedros2608 Жыл бұрын
1:45 I tried the exact same code but I keep getting the following error message "SyntaxError: Cannot declare a const variable twice:" Any help would be appreciated 😀
@bananatop6059
@bananatop6059 Жыл бұрын
I just watched your "JavaScript ES6 Arrow Functions Tutorial". You say that you should always use arrow function unless you have a good reason not to. In most of your recent videos you use functions, not arrow function. Have you had a change of mind?
@shifronim8950
@shifronim8950 Жыл бұрын
Hi, check up your sound. Something eating your words, listen 11:00
@collinl.179
@collinl.179 Жыл бұрын
I can not see the video, (only sound).
@harunjonuzi
@harunjonuzi 10 ай бұрын
Why did he write moduleScript.js, but that .js file was actually not declared in the html file?
@sureshanandsekar4384
@sureshanandsekar4384 6 ай бұрын
That is just to show case the module concepts like exports , imports . it s not necessary to load it in .html file. as far as i know
@marvinjones689
@marvinjones689 Жыл бұрын
Do u mentor
@raymondbyczko
@raymondbyczko Жыл бұрын
I like using the type="module" designation, and then do the import within it. If I then actively add imported functions to button click bindings (using a bit of jQuery), they do not go away, since they are in the DOM (correct me if I am wrong). Even though the module will go away after its processed. Something like this (just adding my 1 cent and excuse the blade notation). This is for a trail/trip planner app I am writing: import {stopAdvance, updateTrailList} from "/js/geolocation.js"; $('#trail_prev').click(()=>{ let current = $('#trail_controller_index_data').data('current'); if (current == 0) { return; } current = current - 1; updateTrailList(current, {{ $max }}, {!! count($list) !!}); $('#trail_controller_index_data').data('current', current); }); . . The above is recent working code fragment. If I recall doing the following does not work: Probably due to the inability to use *import* with the *src*.
@geetanshusharma3727
@geetanshusharma3727 Жыл бұрын
I am here
@eduardoburquezsanz1910
@eduardoburquezsanz1910 Жыл бұрын
Hi! I like your channel, but you talk so fast, I'm not native english speaker and can't follow you, but it's very interesting for me. I've to put on you the speed to .75 Please!
@adarsh-chakraborty
@adarsh-chakraborty Жыл бұрын
First?
@wisdomngwueche469
@wisdomngwueche469 Жыл бұрын
I wish you can be my personal teacher holding by my hand. I can work for you for free for a while. Please consider my offer.
@josenunez8314
@josenunez8314 9 ай бұрын
this guy is the most 2000's looking guy I have ever seen.
@piotrszczesniak
@piotrszczesniak Жыл бұрын
@learningjoe1823
@learningjoe1823 Жыл бұрын
Hey codingwithgaurav(Dodo) here.
@iambrijeshtoo
@iambrijeshtoo Жыл бұрын
Thank you!
JavaScript Was So Bad They Had To Add A Second Mode To Fix It
12:54
Web Dev Simplified
Рет қаралды 64 М.
Learn JavaScript Event Listeners In 18 Minutes
18:03
Web Dev Simplified
Рет қаралды 571 М.
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 108 МЛН
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 24 МЛН
#39 Understanding JavaScript Scope | JavaScript Full Tutorial
16:11
Learn JavaScript CLOSURES in 10 minutes! 🔒
10:58
Bro Code
Рет қаралды 13 М.
Learn JavaScript DOM Traversal In 15 Minutes
14:44
Web Dev Simplified
Рет қаралды 221 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 460 М.
Learn DOM Manipulation In 18 Minutes
18:37
Web Dev Simplified
Рет қаралды 1 МЛН
Top 6 React Hook Mistakes Beginners Make
21:18
Web Dev Simplified
Рет қаралды 562 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН