Javascript
| // | Comment |
|---|---|
| /* */ | Multiline Comment |
| var | Declares a mutable variable |
| let | Declares a variable that can only be declared once |
| const | Read only variable, cannot be changed |
| string.length | Length of a string |
| parseInt(string) | Returns a int with a string argument |
| var array = [] .push() .pop() .shift() .unshift() | Creates an array: can be nested. Pushes date to the end of the array Pop a value off the end of an array Removes the first element in a list Add elements to the beginning of an array |
| Function functionName(parameters) functionName(arguments) | Creates a function Calls a function |
| if (condition) && | |
| else | Else statement |
| switch (variable): Case1: something happens; break; …… | Switch statements between different cases. |
| while (condition) | While loop |
| for (let i=0; i<$; i++) | For loop |
| Do } while (condition) | Another way of doing a for loop (Difference in number of executions) |
Javascript Objects:
- Objects are treated like python dictionaries
- Can be assessed using bracket notation or dot notation