JavaScript ES6 1: Compare Scopes of the var and let Keywords | FreeCodeCamp

preview_player
Показать описание
🍃 **"Journey Through JavaScript: The Power of Scope with 'let' vs 'var'"** 🌳

Hello, Tranquil Coders and Curious Minds! 🌼

Immerse yourself in a meditative dive into the serene yet intricate world of JavaScript scopes. Understanding the differences between the `var` and `let` keywords is not just about writing code; it's about crafting the intention behind every line, ensuring clarity and precision in your script's universe. 🌌✨

🔍 **Scope Out the Difference**:

- **The 'var' Voyage**: Recognized globally or within a function, `var` has been our trusty companion since the dawn of JavaScript. But its vast reach sometimes leads to unexpected twists! 🌍🌀
- **The 'let' Landscape**: As we step into the enchanted lands of ES6, the `let` keyword offers a fresh perspective. It confines its scope, ensuring that what happens in a block, stays in that block. It's the Zen master of JavaScript variables! 🌳

**Example Encounters**: Take a moment to reflect upon our examples:
1. A loop using `var` presents a global reveal, where `i` spills its secrets for the world to see! 🌎💡
2. While its counterpart, a loop powered by `let`, maintains the sanctity of the loop's realm, protecting the essence of `i`. 🏞️🔒

📝 **Mindful Mission**: As you embark on this exercise, your challenge is to ensure that the `i` in the if statement maintains its own identity, distinct from the `i` introduced at the function's onset. Remember, inner peace in coding comes when variables live harmoniously in their designated scopes. 🌙🧩

**#JavaScriptZen #ScopeJourney #MindfulCoding #LetVsVar #EmbraceES6** 🍃🔍🌟📖

📚 Further expand your web development knowledge:

💬 Connect with us:

#freecodecamp #coding #learntocode #learnprogramming #learnjavascript l #javascript #frontend #frontenddeveloper #programming #programminglife #computer #computerscience #computers #homework #learning #tutorial #programmingtutorials #programmingtutorial #javascripttutorial #javascripttutorialforbeginners #javascripttutorials #code #codes #responsivewebdesign #tutorial #tutorials #learn2code #style #build #ES6 |
Рекомендации по теме
Комментарии
Автор

var printNumTwo;
for (var i = 0; i < 3; i++) {
if (i === 2) {
printNumTwo = function() {
return i;
};
}
}
console.log(printNumTwo());
Here the console will display the value 3.

im confuse ..how come it became 3? i tried to follow it and im stuck in the if(i====2) ...

lavielle