deeper still into js (coding diary #8)

Michael Scoggins |
7/26/2020

1. Describe one thing youâre learning in class today.
i learned how higher order functions work, and how to design them from scratch using a vanilla for loop. i learned that higher order functions use more basic functions such as .pop()
and .push()
(such as .filter()
) to carry out their jobs.
2. Can you describe the main difference between a forEach loop and a .map() loop and why you would pick one versus the other?
a forEach() loop will simply run a function on each item inside an array, thereby possibly mutating that array permanently (and always return âundefinedâ). a .map() loop on the other hand will return a new array after passing through some function, thereby creating a âtransformed array.â obviously very useful.
3. Describe event bubbling.
event bubbling is the property of eventListeners that determines whether it will âbubble upâ to parent elements if it is not itself assigned the event. so that it will keep bubbling up until it finds its target, or else âpopâ once it gets to the window object. what i donât understand is how an event wouldnât find its target in the first place.
4. What is the definition of a higher-order function?
a higher-order function is a function which has as at least one of its arguments another function. itâs really that simple!
5. ES6 Template Literals offer a lot of flexibility in generating strings. Can you give an example?
let greeting = âhello worldâ
console.log(`${greeting}`)
which would print "hello world" (literally) to the console.
6. What Is an associative array in JavaScript?
ok here goes (and this might be misguided): in JS all arrays are objects. objects however, are not arrays. But, they are sometimes referred to as âassociative arrays,â because they contain key-value pairs that are âassociatedâ with one another.
7. Why should you never use new Array in JavaScript?
because there is literally no reason to. just say let array = [1,2,3] and boom you have a ânew arrayâ with that same ânew Arrayâ smell.