Loops, Functions and Non-Arrays. Describe one thing you’re learning in…
Tags: Arrays, Coding, Codingbootcamp, Developer, Austin Coding Academy

Describe one thing you’re learning in class today.

That we should never attempt to change the parameters given to you when working with someone else’s functions as it will not return ultimately desired result.

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

While both forEach and .map() function much like a forLoop, forEach is closer to the original function since it is just iterating through the array without alternating it and will return the single element from the array when requested.map(), on the other hand will iterating through the array and create a whole new one of key value pairs.

3. Describe event bubbling.

Think being under water, you’re at the bottom of a pool and you let out a little bit of air, what happens? A bubble of air escapes and floats to the top. In very basic terms that is what event bubbling is. There is an event that occurs on your webpage, such a clicking on a button, which triggers that event to travel up your DOM tree to the top. It’s almost like daisy chaining up your DOM until it reaches to the top. Trouble is, this means when you a using the child, it will ultimately effect the parent as well.

The other term used for this phenomena is propagation, which also happens to be one of the key terms used to prevent this from happening. You can add stopPropagation()

to your event to prevent your bubble from floating to the top.

A wonderful resource I found to explain this was from JavascriptInfo and also the ever wonderful Eloquent Javascript

4. What is the definition of a higher-order function?

This is when a function and takes another function as an argument, these are usually reusable and make your code more accessible and less prone to errors since many of these higher-order functions are built into javascript. Some of these include, .filter(), .map(), .forEach().

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

the thing I recently did with template literals I think expresses their flexibility, I converted a string into a regular expression with the correct formatting using a template literal. They make it possible to use any number of outputs and convert them into strings. This can make so many things simpler.

6. What Is an Associative Array in JavaScript

An Associative Array is another term for Objects. It is another way we can format them, usually in the cases where the syntax of key requires bracket notation. Unlike objects though, these are not contained within curly brackets, but stated as individuals. You access them the way you normally would an object, but are required to use the bracket notation instead of dot notation.

What does this mean though? These are another format of an object. These are not arrays and do not function as one. You cannot access these key value pairs using the indexes and you cannot use methods associated with arrays.

7. Why should you never Use New Array in JavaScript?

New Arrays are constructors and take up a lot of memory. The other major issue with them is standard array method do not function predictively; such as length. If you use length in a New Array, it will return the value of the contains, but the actual length of the array. New Array also do not allow index access. If you try to access an individual value by using the index, it will return undefined.