w3School course
Course
| Keyword | Description |
|---|---|
| var | Declares a variable |
| let | Declares a block variable |
| const | Declares a block constant |
| if | Marks a block of statements to be executed on a condition |
| switch | Marks a block of statements to be executed in different cases |
| for | Marks a block of statements to be executed in a loop |
| function | Declares a function |
| return | Exits a function |
| try | Implements error handling to a block of statements |
varkeywords được sử dụng trong JS code từ 1995 - 2015. Hiện nay, chỉ nên dùngvarkhi code cần support cho các trình duyệt cũ.letvàconstđược thêm vào JS code từ 2015.
Sử dụng const, let, var khi nào?
- Always declare variables
- Always use
constif the value should not be changed - Always use
constif the type should not be changed (Arrays and Objects) - Only use
letif you can’t useconst - Only use
varif you MUST support old browsers.