Functions Flashcards
ES6 distinguishes between 2 types of functions. What are they?
Callable (cannot be called with new) Constructable (can be called with new, return an object)
Functions created via the arrow function syntax or via a method definition / object literals are not ….
Constructable
When I create a function, how do I make it NOT a constructor?
To create a function that is not constructable, you can use an arrow function.
What is the default return value of a function?
Undefined
When defining a function, the identifiers that are placed within the brackets are called …
Parameters
When identifiers or variables are passed into a function for execution, they are known as …
Arguments
What are 4 unique properties of an arrow function?
- It does not have its own this
- It does not have its own arguments
- It does not its own super
- It does not have its own new.target
Can arrow functions be used as constructors?
No. They are callable, not constructable. They do not pass on a this context.
If arrow functions do not have their own this value, how does this take its value within the function?
The this value of the enclosing lexical scope is used, e.g. arrow functions follow the normal variable lookup rules.
What 4 steps happen automatically when invoking a function as a constructor?
- ) A new object is created (O)
- ) the new object is [[Prototype]]-linked (P)
- ) the new object is set as the ThisBinding for the function’s execution context (E)
- ) the new object is returned* (N)
O.P.E.N.
* Unless the function overrides this with its own explicit return