From the course: Master Next.js: Elaborate Hands-On Web Development, React Basics, Advanced Next.js, and Deployment
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
How scope works in JavaScript
From the course: Master Next.js: Elaborate Hands-On Web Development, React Basics, Advanced Next.js, and Deployment
How scope works in JavaScript
OK, so we looked at function hoisting and we mentioned this concept of scope. We said that JavaScript will move the functions, only declarative functions, or hoist them to the top in its current scope. We briefly defined the scope for this file. We said, well, if we only have this one file and there's only one function and one console.log, then the scope here really is the global scope. So even if it's below, it's not going to break. It's still going to return not undefined because it's being hoisted. But what the heck is FunctionScope really? And how does it work in JavaScript exactly? It's not complicated, but it's extremely important. So let's review FunctionScopes together. So we're going to make a new file. And we can call this function-scope.js, just one s, Sorry, and we can close the hoisting one. You can save the changes. And let's talk about function scopes. So function scopes. So variables in a function cannot be accessed from anywhere outside the function. You know, let's…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Download Node.js and what is Node.js?2m 23s
-
(Locked)
Setting up our learning environment5m 42s
-
(Locked)
What are functions in JavaScript?9m 42s
-
(Locked)
Example of how functions work in JavaScript for complete beginners9m 18s
-
(Locked)
What are function expressions in JavaScript?9m 28s
-
(Locked)
JavaScript interview question trick with function expressions and utility fun16m 14s
-
(Locked)
What is function hoisting in JavaScript?6m 37s
-
(Locked)
How scope works in JavaScript15m 53s
-
(Locked)
What are closures and an example with JavaScript explained?11m 49s
-
(Locked)
Advanced closure module pattern with data privacy encapsulation15m 16s
-
(Locked)
What are arrow functions and usefulness in React?17m 13s
-
(Locked)
Destructuring with JavaScript23m 1s
-
(Locked)
-
-
-
-
-
-
-
-