Jinsi ya Kufahamu Scope na Hoisting katika JS
Hoisting: variables/functions are lifted
Example Code:
<script>
// Hoisting example
console.log(hoistedVar); // undefined
var hoistedVar = 10;
// Scope example
let globalVar = "Global";
function testScope() {
let localVar = "Local";
console.log(globalVar); // accessible
console.log(localVar); // accessible
}
testScope();
// console.log(localVar); // Error: localVar not defined
</script>
YouTube Description:
Jifunze hoisting na variable scope za JavaScript kwa beginners.
Hashtags:
#JSScope #Hoisting #Faulink
Tembelea https://www.faulink.com kupata mifumo yote muhimu