Assignment: Understanding Scope of var, let and const in JavaScript

Learn how scope and variable declarations work together in JavaScript. This beginner-friendly lesson walks through multiple examples to show the difference between var, let, and const, including how they behave in the global scope and inside blocks. You will see why var attaches to the window object, while let and const do not. Using execution context diagrams, we explain hoisting, the temporal dead zone, and why accessing let or const before declaration throws an error. We also explore function scope, block scope, and how scope affects variable lookups. Timeline 0:00 Introduction to scope, var, let, and const 0:47 var attaches to the window object 2:18 var declaration initialized with undefined 3:04 Output check: 1 and 2 4:35 Declaration phase: var variables set to undefined 5:21 const declaration not initialized 6:06 Error: cannot access const before initialization 7:36 Variable awesome is undefined 8:21 Function fullName with firstName and lastName 9:09 Defining variable using var 9:56 Logging username value 10:42 Looping over arguments 11:27 Block scope with if true 12:12 Calling outer and inner functions 12:57 Calling x trainer inside inner Explore more at AltCampus: https://altcampus.com