Error about using var
@alhassy đang làm issue này rồi.
Từ ngày 27/1/2021.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 221
- Fork
- 23
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của alhassy/JavaScriptCheatSheet
-
Missing function scope Đang mởhelp wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
-
help wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 50/100
alhassy/JavaScriptCheatSheet#5 · 2 bình luận ·
-
help wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 55/100
alhassy/JavaScriptCheatSheet#2 · 1 bình luận ·