Day 3: Scope & Default Parameters
Daily Objective
Section titled “Daily Objective”Understand variable accessibility across scopes and assign fallback default parameters.
1. Scope (Global, Function, Block)
Section titled “1. Scope (Global, Function, Block)”const globalVar = 'Accessible everywhere';
function demoScope() { const functionVar = 'Only inside demoScope'; if (true) { const blockVar = 'Only inside this if block'; console.log(blockVar); } // console.log(blockVar); // ReferenceError!}2. Default Parameters
Section titled “2. Default Parameters”function greetUser(name = 'Guest', greeting = 'Welcome') { return `${greeting}, ${name}!`;}console.log(greetUser()); // "Welcome, Guest!"console.log(greetUser('Alice')); // "Welcome, Alice!"Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Create a function with 2 default parameters and invoke it with 0, 1, and 2 arguments.
- Intentionally try reading a block-scoped variable outside its curly braces.