Variable Instantiation
the value assigned can be referenced in later parts of the program through variableName. Only one value can be assigned to one variable, i.e one instantiation per variable, if let var1 = 'string' previously, cannot let var1 = 2 again later in the code Operators
|
Data Types
Array
- initialized with square brackets - can contain all data types, including arrays and objects - ordered list of values, starting from index 0 to refer to first element - get item in array by referring to its index (array[0] gets 'string', array[1] gets 2) Object
similar to array, but replace index with key(string) can contain all data types, including arrays and objects refer to objects in 2 ways 1. object.key1 gets value1 2. object['key2'] gets value2. when using square brackets, put the key in string format Function Examplelet num1 = 1; let num2 = 20; let result = addTogether(num1, num2); num1 and num2 becomes firstNum and secondNum respectively if no return value, calculations done in the function cannot be carried out of the function function addTogether(firstNum, secondNum) { return firstNum + secondNum; } result will get the returned value of 21 |
Loops
loop (condition) { execute code in block } for for has multiple uses 1.a condensed while loop for (let i = 0; i< 10; i++) {} 2. To loop through an array/object let numbers = [20, 30, 10, 50, 70]; for (let number of numbers) { use value each loop uses number = 20, then 30, 10 ... } for (let numbers in numbers) { use index/key each loop uses number = 0, then 1, 2 ... to get value, use numbers[number] (object[index]) } Function
functions are called with brackets -> foo() if function has parameters, function must be called with parameters -> foo(param) parameters are assigned to new names for usage in the function (see below) |
Cheatography
https://cheatography.com
Basic Programming Cheat Sheet by tegdsd12
Basic Programming 1111
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets