storm looper
Describe one thing you’re learning in class today.
A regular expression (or regex) is a way to filter a sequence of characters that matches a certain defined pattern. The sometimes cryptic looking patterns are extremely powerful in finding a certain type of string, like a phone number for example. To match a standard US ten-digit phone number the regex would look something like this: ^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
It is a valuable skill to learn but there are also luckily many resources on the internet to find nearly any regex expression you could dream of.
Can you describe the main difference between a forEach loop and a .map() loop and why you would pick one versus the other?
.map()
returns a new array while .forEach()
returns undefined. Each is passed a callback function and a callback function in a .forEach()
may mutate the original array while .map()
will always return a new array. .map()
is also chainable while .forEach()
is not. If you want to return an array then .map()
is a good option, otherwise .forEach()
might be a better way to loop over an array.
Describe event bubbling.
Event bubbling is related to the HTML parent/child relationship. For example, if you have an event attached to a child element and a parent element then that event will “bubble” out and affect both the parent and child element’s respective events.
What is the definition of a higher-order function?
A function that can take another function as an argument or that returns a function as a result.
ES6 Template Literals offer a lot of flexibility in generating strings. Can you give an example?
Template literals are a much cleaner way to concatenate strings together where you don’t have to worry as much about putting quotes and + in the correct positions. Simply begin your string with a backtick `
then anytime you want to use a JS expression after a dollar sign and surrounded bystanders curly brackets ${…}
What is an associative array in JavaScript?
Another name for a JS object with a key-value pair surrounded by curly brackets {key: value}
Why should you never use new Array in JavaScript?
You should always use an array literal to define an array in JS. If you use a new array constructor, the output will have unpredictable and non-intuitive behavior. In fact, it will not return an array at all but will rather return an element array with all the elements defined.