[Guide] ES6: Compare var and let scopes. Fixes and enhancements. (#34636)
* [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
This commit is contained in:
committed by
Randell Dawson
parent
e4870c472a
commit
772f4e1c40
@ -1,22 +1,20 @@
|
||||
---
|
||||
title: Compare Scopes of the var and let Keywords
|
||||
---
|
||||

|
||||
|
||||
 Remember to use <a>**`Read-Search-Ask`**</a> if you get stuck. Try to pair program  and write your own code 
|
||||
|
||||
### Problem Explanation:
|
||||
## Problem Explanation:
|
||||
|
||||
We need to change `var` to `let` in our function scope and add `let` to our block scope.
|
||||
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
|
||||
|
||||
* Find `var` and replace with `let`.
|
||||
* _Be certain not to use the `var` keyword anywhere in your code._
|
||||
|
||||
> _try to solve the problem now_
|
||||
|
||||
* Add `let` to the variable `i` inside of your if statement.
|
||||
|
||||
* _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!
|
||||
@ -38,21 +36,13 @@ We need to change `var` to `let` in our function scope and add `let` to our bloc
|
||||
return i;
|
||||
}
|
||||
```
|
||||
 <a href='https://codepen.io/dylantyates/pen/wxwxRd' target='_blank' rel='nofollow'>Run Code</a>
|
||||
|
||||
# Code Explanation:
|
||||
|
||||
## Code Explanation:
|
||||
|
||||
By using `let` you can declare variables in relation to their scope.
|
||||
|
||||
#### Relevant Links
|
||||
|
||||
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let' target='_blank' rel='nofollow'>let</a>
|
||||
|
||||
##  NOTES FOR CONTRIBUTIONS:
|
||||
|
||||
*  **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
|
||||
* Add an explanation of your solution.
|
||||
* Categorize the solution in one of the following categories — **Basic**, **Intermediate** and **Advanced**. 
|
||||
* Please add your username only if you have added any **relevant main contents**. ( **_DO NOT_** _remove any existing usernames_)
|
||||
|
||||
> See  <a href='http://forum.freecodecamp.com/t/algorithm-article-template/14272' target='_blank' rel='nofollow'>**`Wiki Challenge Solution Template`**</a> for reference.
|
||||
### Resources
|
||||
- ["let" - *MDN Javascript reference*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let)
|
||||
- [Rauschmayer, Axel. "Variables and scoping in ECMAScript 6". *2ality.com*, 2015-02-07.](http://2ality.com/2015/02/es6-scoping.html) Accessed 11 Dec 2018.
|
||||
- [Bos, Wes. "Quick Tip: Use let with for Loops in JavaScript". *wesbos.com*, 16 Aug 2016.](https://wesbos.com/for-of-es6/) Accessed 11 Dec 2018.
|
||||
|
Reference in New Issue
Block a user