We’ve hit our second halfway point.

Mary Wenzel
2 min readNov 9, 2020

Describe one thing you’re learning in class today.

I learned something new in JavaScript today (more new stuff of course) being .find(), and .findIndex().

.find() finds the first element in an array that passes a test. So if you had an array like

const findYear = [1994, 1995, 1998]

you can use .find() to locate the first number greater than 1994. Then you can use the .findIndex() to return where in the array that number is, or its index.

Can you describe the main difference between a forEach loop and a .map() loop and why you would pick one versus the other?

forEach() executes whatever the function is once for each element of an array element while map() creates a new array with the results of calling a provided function on every element in the calling array.

Describe event bubbling.

By default, events bubble in JavaScript. Event bubbling is when an event will traverse from the most inner nested HTML element and move up the DOM until it arrives at the element which listens for the event. ex:

/ \
---------------| |-----------------
| element1 | | |
| -----------| |----------- |
| |element2 | | | |
| ------------------------- |
| Event BUBBLING |
-----------------------------------

the event handler of element2 fires first, the event handler of element1 fires last.

What is the definition of a higher-order function?

a higher-order function is a function that does at least one of the following:

  • takes one or more functions as arguments
  • returns a function as its result.

ES6 Template Literals offer a lot of flexibility in generating strings. Can you give an example?

Template literals are a great way of putting strings together, say if I wanted to console log a statement like “This is the .. of my Car” and insert my value between the text I could do it like this.

console.log(‘This is the” + value + “of my Car”)

Now that works perfectly fine, but you can shorten it with template literals by using backticks (`) and curly brackets ({}) which would look like this.

console.log(`This is the ${value} of my Car`)

What Is an associative array in JavaScript?

This is another name for a JavaScript object with a key and a value surrounded by curly brackets {key: value}

Why should you never use new Array in JavaScript?

If you were to use new Array as a constructor the output will have an unpredictable behavior. It won't actually return an array either but will return an element array with only the elements defined.

--

--