Error about using var
@alhassy y travaille déjà.
Depuis le 27/1/2021.
Évaluation
Cette issue n'a pas encore été évaluée.
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.
- Langage dominant
- Aucune donnée de langage
- Étoiles
- 221
- Forks
- 24
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de alhassy/JavaScriptCheatSheet
-
Missing function scopeOuvertehelp wanted
Difficulté 1/5 Moins d'une heure Accessibilité débutants 70/100
-
help wanted
Difficulté 1/5 Moins d'une heure Accessibilité débutants 50/100
alhassy/JavaScriptCheatSheet#5 · 2 commentaires ·
-
help wanted
Difficulté 1/5 Moins d'une heure Accessibilité débutants 55/100
alhassy/JavaScriptCheatSheet#2 · 1 commentaire ·