ls
, cd
, pwd
to their descriptions
ls
lists contents of current directorycd
changes current directory
cd ..
takes you up one levelcd
alone takes you back homepwd
returns current directoryconsole.log('hello new world');
and save it.Label variables as either Primitive vs. Reference
Identify when to use .
vs []
when accessing values of an object
object.key
object["key]
Write an object literal with a variable key using interpolation
put it in brackets to access the value of the variable, rather than just make the value that string
let a = 'b';let obj = { a: 'letter_a', [a]: 'letter b' };
Use the obj[key] !== undefined
pattern to check if a given variable that contains a key exists in an object
(key in object)
syntax interchangeably (returns a boolean)Utilize Object.keys and Object.values in a function
Object.keys(obj)
returns an array of all the keys in obj
Object.values(obj)
returns an array of the values in obj
Iterate through an object using a for in
loop
let printValues = function (obj) { for (let key in obj) { let value = obj[key]; console.log(value); }};
Define a function that utilizes ...rest
syntax to accept an arbitrary number of arguments
...rest
syntax will store all additional arguments in an array
array will be empty if there are no additional arguments
let myFunction = function (str, ...strs) { console.log('The first string is ' + str); console.log('The rest of the strings are:'); strs.forEach(function (str) { console.log(str); });};
Use ...spread
syntax for Object literals and Array literals
let arr1 = ['a', 'b', 'c'];let longer = [...arr1, 'd', 'e']; // ["a", "b", "c", "d", "e"]// without spread syntax, this would give you a nested arraylet withoutRest = [arr1, 'd', 'e']; // [["a", "b", "c"], "d", "e"]
Destructure an array to reference specific elements
let array = [35,9];
let [firstEl, secondEl] = array;
console.log(firstEl); // => 35
console.log(secondEl); // => 9