- Describe the biggest difference between
.forEach&.map..forEachdoes not return any value of the array it is iterating over, while.mapreturns a new array with converted values from the array it is iterating through.
- What is the difference between a function and a method?
- A method is a function that is contained inside an Object as a property, while a function has either global or local scope without it being a property of an Object.
- What is closure?
- Closure is the combination of a function and the lexical environment within which the function was declared. This means functions are able to access variables declared in their scope chain—the enclosing function's variables or global variables or both, but not backwards.
- Describe the four rules of the 'this' keyword.
- Default window - the
thiskeyword references the Window Object by default. - Implicit Binding - when a method is called, the
thiskeyword will reference the Object closest to the method call—meaning the Object on the left side of the.that separates the Object and the method's name. - New Binding - when creating a new Object using a constructor function, the keyword
newwill assign a newthisreference to the Object it is creating. - Explicit Binding - the
thiskeyword is assigned to a specific Object using the.call(), .apply(), or .bind()methods.
- Default window - the
- Why do we need super() in an extended class?
super()is required in order for the Object to access its parent Object's functions.