Error about using var
@alhassy ya está trabajando en esto.
Desde el 27/1/2021.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- Sin datos de lenguaje
- Estrellas
- 221
- Forks
- 23
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de alhassy/JavaScriptCheatSheet
-
Missing function scope Abiertohelp wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
-
help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 50/100
alhassy/JavaScriptCheatSheet#5 · 2 comentarios ·
-
help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 55/100
alhassy/JavaScriptCheatSheet#2 · 1 comentario ·