Skip to content

Instantly share code, notes, and snippets.

@erockdotdev
Created May 9, 2017 02:19
Show Gist options
  • Save erockdotdev/9e9cb83dd615afe1d8f7ba98238088bd to your computer and use it in GitHub Desktop.
Save erockdotdev/9e9cb83dd615afe1d8f7ba98238088bd to your computer and use it in GitHub Desktop.
hw-u03-w07-d01-js-reading

In a seperate markdown file, answer the following questions in no more than a few sentences. Please cut and paste the questions into the file you create.

  1. What are some advantages to using Javascript's built in iterator methods over writing you're own for loops? Javascript's built in iterator methods revove the need for setting counters like in a for or while loop. They also keep our code DRY as they are easily resuable vs a for loops that written for differnte arrays and outputs. Also, filtering option are semantic so its easy for someone else lookign at the code to know what the result is supposed to be.

  2. What is the difference between map and forEach? The difference between map and forEach is that map actually chnages the data and post to a new array while for each does someting with that data like presenting it, or moving it but not transforming it.

  3. What data type will filter return? Filter will return an array.

  4. What's a simple use case for reduce? Reduce reduces an array doen to a single value based on a condition. For example, finding the largest number in an array.

  5. Suppose Javascript had no map method, how would you write it? If Javascript had no map method I would write function map (f,a) // a function tat takes 2 arguements, a function and an array. let output = [] // this will hold the result of maping the array and the function. for (let item of a){ // a for...of loop that takes the array and assigns it to item. output.push(f(item)); // here the function runs on each index of item and takes that result and pushes it to the output array } return output; }

  6. What is a Javascript prototype? Its the partent of an object and is how a particular object inherits properities.

  7. What is a prototype chain? What is an example? every object has an internal property that links to another object and that one links to another object prototype this contines until the Object prototype. after that is null which has no prototype

  8. What is the Javascript data type that has no prototype? Null has no prototype

  9. How does Object.create() affect the prototype chain? Object.create() creates a new object and what is pased as an arguement is what become that objects prototype. That effects the prototype chain bye intentionaly choosing what this objects prototype will be.

  10. How do you check to see if an object has a property defined on itself rather than somewhere up the protoype chain? Object.getOwnPropertyNames(obj) - returns all keys of an object, but not inhereted keys and, Object.keys(obj) return all enumerable keys of an object (properities created by the user)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment