Skip to content

Instantly share code, notes, and snippets.

@GermanHoyos
Created December 11, 2017 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GermanHoyos/35537b1d60bca5dd14edf0ed698f5f38 to your computer and use it in GitHub Desktop.
Save GermanHoyos/35537b1d60bca5dd14edf0ed698f5f38 to your computer and use it in GitHub Desktop.
<script>
let x = arr[i] || ' '; // <-- if arr[i] is falsy (doesnt return a value) x will be the string or the value after the ||
// run a for loop on two conditions being OR true, once one isnt true the other is checked for truth
let indexZro = array[0];
let indexOne = array[1];
for (let i = 0; i < indexZro.length || i < indexOne.length; i++)
//use a object to change global variable localy without declaring locally
let x = 0;
foo();
function foo(){
myObj = {
x: x // or just x <--- must remember though k name is inmutable
}
for (let i = 0; i < 10; i++){
console.log(x);
x++;
} return x; // <---- fix 'undefined' // will return undifined if function doesnt 'return'
}
//input into a string values or strings
results += (X + ' ' + Y);
//input into an array values or strings
arr.push(X + ' ' + Y); // you can add as much as you want into an index
arr.push('\n'); //<---- this will be in its own index
arr.push(X + ' ' + Y + '\n'); //<--- '\n' will be in same index as X and Y'
//logical operators
1 == '1' //true
1 === '1' //false
a5 = 'Cat' && 'Dog' // returns dog
a5 = 'Cat' || 'Dog' // returns cat
bCon1 || (bCon2 && bCon3) //ither bCon1 is true/false OR (bCon2 AND bcon3) is true/false
//Callback Functions- to be used when one function needs to
//wait for the completion of another
let family = ['wife','son','sister'];
function fooOne(family, callback){
// do something that takes 1 minute
callback();
}
function fooTwo() {
//do something that only takes 30 seconds
// this is 'called back' after completion of 'fooOne'
}
fooOne(family, fooTwo);
// Test for undefined
if (x === undefined) {
// these statements execute
}
//Execute for each index in an array
let array = ['index_0','index_1'];
array.forEach(foo); // foo = built function
//deep dig into objects key and properties
var myObj = {
locations: {
cities: ['Boston', 'New York', 'Baltimore', 'Miami']
}
}
console.log(myObj.locations.cities[2]); //=> baltimore
console.log(myObj['locations']['cities'][0]); //boston
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment