Error about using var
@alhassy is already working on this.
Since Jan 27, 2021.
Assessment
This issue has not been assessed yet.
Description
In the same way, for the same purpose, we may use
varbut it has undesirable properties; e.g., its declarations are in the global scope and no error is raised usingvar x = ⋯ifxis already declared.
This is at the end of the Types section. First bullet point of three.
The part that says "its declarations are in the global scope" is incorrect.
Later, in the Scope and Statements section, you say...
let,constdeclare local bindings;varalways makes global ones!
Which again is incorrect. You can try this...
function f() {
var x = 1;
}
console.log(x); // => Uncaught ReferenceError: x is not defined
...and see that x is not defined in the global scope. It will be local to the f function.
The difference about var and let in what regards scope is:
varbindings reach either function scope or the global scope.letbindings can also be limited to block scope.vardeclarations are hoisted to the start of the scope.letbindings are not (*)
(*) To be more precise they are but have a mechanism that prevents usage before declaration and will throw an error, while var won't.
- Dominant language
- No language data
- Stars
- 221
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from alhassy/JavaScriptCheatSheet
-
help wanted
Difficulty 1/5 Under an hour Newbie friendliness 70/100
-
help wanted
Difficulty 1/5 Under an hour Newbie friendliness 50/100
alhassy/JavaScriptCheatSheet#5 · 2 comments ·
-
help wanted
Difficulty 1/5 Under an hour Newbie friendliness 55/100
alhassy/JavaScriptCheatSheet#2 · 1 comment ·