* [Guide] ES6: Compare var and let scopes. Fixes and enhancements. - Remove phantom image - Remove notes for contributors - Change explanation and hints so they don't provide the solution too early. - Links to markdown + 2 more resources * Update guide/english/certifications/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords/index.md Co-Authored-By: AdrianSkar <adrian@adrianskar.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords/index.md Co-Authored-By: AdrianSkar <adrian@adrianskar.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords/index.md Co-Authored-By: AdrianSkar <adrian@adrianskar.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords/index.md Co-Authored-By: AdrianSkar <adrian@adrianskar.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords/index.md Co-Authored-By: AdrianSkar <adrian@adrianskar.com> * fix: clarified the hint regarding variable i
2.1 KiB
2.1 KiB
title
| title |
|---|
| Compare Scopes of the var and let Keywords |
Remember to use Read-Search-Ask if you get stuck. Try to pair program
and write your own code 
Problem Explanation:
Change the code so that the variable i declared in the if block is separately scoped than the variable i declared at the beginning of the function.
Hint: 1
- Be certain not to use the
varkeyword anywhere in your code.
try to solve the problem now
- Remember that
let's scope is limited to the block, function or statement in which you declare it.
try to solve the problem now
Spoiler Alert!
Solution ahead!
Basic Code Solution:
function checkScope() {
"use strict";
let i = "function scope";
if (true) {
let i = "block scope";
console.log("Block scope i is: ", i);
}
console.log("Function scope i is: ", i);
return i;
}
Code Explanation:
By using let you can declare variables in relation to their scope.
