JavaScript Syntax
JavaScript Comments
Comments are used to explain the code and make it more readable.
Comments are created in JavaScript using the // syntax.
To create a multi-line comment, use the /* and */ syntax.
JavaScript Variables
Variables are declared with the let or const keywords.
Selected Variable: None
NOTE: A const variable MUST be assigned a value when it is declared.
NOTE: A variable name CANNOT contain hyphens, as in JavaScript they are reserved for subtraction. For example,
let variable-name = 10; is invalid, but let variableName = 10; is valid.
JavaScript Keywords
Keywords are reserved words that are used to declare variables, functions, and other elements in JavaScript.
| Keyword | Description |
|---|---|
| let | Declares a variable |
| const | Declares a constant |
| var | Declares a variable (NOT RECOMMENDED FOR MODERN JS) |
| function | Declares a function |
| return | Returns a value from a function |
| if | Checks if a condition is true |
| else | Executes code if the condition is false |
| while | Executes code while a condition is true |
| for | Executes code a specified number of times |
| break | Exits a loop |
| continue | Skips to the next iteration of a loop |
| try | Executes code that may throw an error |
| catch | Executes code if an error is thrown |
NOTE: There are many more keywords in JavaScript, but these are the most commonly used.