Created
March 4, 2020 20:50
-
-
Save manegame/f096bbbf3114da2ee44c573468f16f61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let people = ['Jack', 'John', 'James']; | |
let colors = ['red', 'blue', 'green']; | |
console.log(people); | |
console.log(colors); | |
// Length of an array | |
console.log(colors.length) | |
// Add purple | |
colors.push('purple'); | |
console.log(colors); | |
// Add yellow to the beginning | |
colors.unshift('yellow'); | |
console.log(colors); | |
// Remove from end | |
colors.pop(); | |
console.log(colors); | |
// Remove from beginning | |
colors.shift(); | |
console.log(colors); | |
// 0 1 2 | |
// colors ["red", "blue", "green"] | |
// Get the second item from the array | |
// console.log(colors[1]) // blue | |
// Add a name to each color | |
for (let i = 0; i < colors.length; i++) { | |
colors[i] = colors[i] + ' ' + people[i]; | |
console.log(colors[i]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let iAmManus = true | |
let iAmFilmone = false | |
console.log(iAmManus) // true | |
console.log(!iAmManus) // false | |
console.log(!true) // false | |
if (true) { | |
console.log('something') | |
} | |
if (false) { | |
console.log('not something') | |
} | |
// Every variable has a truthy or falsy value | |
// https://developer.mozilla.org/en-US/docs/Glossary/Truthy | |
// https://developer.mozilla.org/en-US/docs/Glossary/Falsy | |
if ('') { | |
console.log('run this?'); | |
} | |
if (0) { | |
console.log('run 0?'); | |
} | |
if (-1) { | |
console.log('run -1?'); | |
} | |
let name = 'Manus' | |
if ('') { | |
console.log('thanks for giving us your name') | |
} else { | |
console.error('fuck you forgot your name') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Key: Value | |
let car = { | |
color: 'blue', | |
engine: 'V8', | |
brand: 'BMW', | |
kilometers: 123378, | |
owner: { | |
name: 'Filmone', | |
gender: 'male' | |
}, | |
previous_owners: [ | |
'Johnny', | |
'Jack', | |
'Maria' | |
] | |
} | |
// Get the owner of the car | |
console.log(car.owner) | |
// What information is in a object? | |
console.log(Object.keys(car)) | |
// Loop over all the keys and output the values | |
Object.keys(car).forEach((key) => { | |
console.log(key) | |
console.log(car[key]) | |
}) | |
car.tyre_thickness = '2mm' | |
console.log(car) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment