Unexplained scopes in ES6: Compare Scopes of the var and let Keywords
See original GitHub issuehttps://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords In this lesson, “block scope” is not explained, at least not so clear as what https://www.w3schools.com/js/js_let.asp does.
The sentence
i
is not defined because it was not declared in the global scope
is especially confusing because if i
is declared with var
in the same situation, the console will not return “i
is not defined”.
The points are:
- What kinds of scope exist?
- What scopes can
var
andlet
have?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Compare Scopes of the var and let Keywords - GitHub
Be certain not to use the var keyword anywhere in your code. This exercise is designed to illustrate the difference between how var...
Read more >ES6: Compare Scopes of the var and let Keywords - JavaScript
Here's the code I have written function checkScope() { "use strict"; let i = "function scope"; if (true) { i = "block scope"; ......
Read more >Variable scope, closure - The Modern JavaScript Tutorial
That's because functions aren't variables. You can however, assign a function to a variable declared with let, const or var. But that is...
Read more >ES6 Tutorial - #2 Let vs. Const, Scope, and Hoisting - Video Explode
00:01:34let us close that and let's go back to 00:01:35latin cons well if you've been using 00:01:38javascript you've probably seen the VAR 00:01:39keyword...
Read more >Why predeclared variables? - #17 by RFluff - Development - scsynth
As much as the edge cases of hoisting are strange, changing scope details ... they introduced a new let keyword in ES6 to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any suggestions @GrimPixel?
I think the challenge as a whole could use some simplification. The code examples feel more complicated than they need to be to illustrate the concept. The description is quite long as well. But that’s a whole rewrite of the challenge. I’m not sure it’s worth it.
oh, sorry, it seems the version I remember was changed before this then