Prompt 204

Describe one thing you’re learning in class today.

We are learning about Regular Expressions. It helps you find keywords or characters that you would have to type out manually.

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

The returning value. The first difference between map() and forEach() is the returning value. The forEach() method returns undefined and map() returns a new array with the transformed elements.

Describe event bubbling.

When a user clicks the button the event first fires on the button itself, then bubbles up to the parent div, and then up to the ancestor div. The event would continue to bubble up through all the ancestors, until it finally reaches the document.

What is the definition of a higher-order function?

Higher order functions are functions that operate on other functions, either by taking them as arguments or by returning them. In simple words, A Higher-Order function is a function that receives a function as an argument or returns the function as output.

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

Template literals provide an easy way to interpolate variables and expressions into strings. You do so by using the ${...} syntax, inside the ${} you can add anything, even expressions.

What Is an associative array in JavaScript?

Associative arrays are basically objects in JavaScript where indexes are replaced by user-defined keys. They do not have a length property like a normal array and cannot be traversed using a normal for loop.

Why should you never use new Array in JavaScript?

They are fundamentally similar. [] is pretty much shortcut for new Array(), so it is preferable. The former is called an array literal/array shorthand. The latter is an example of using the array constructor, which really does the same thing (the array constructor gets called behind the scenes for the literal). The only time you ever want to use new Array(), and not [], is when you want to have a large, empty array.