Callable Values 25 Flashcards
What are the two categories of functions in JS? What do they contain?
Ordinary function: can play several roles
- real function
- method
- constructor function
Specialized function: can play one role
- arrow function can only be a real function
- a method can only be a method
- a class can only be a constructor function
What is an entity?
a JS feature as it lives in RAM. an ordinary function is an entity
What is syntax?
the code we use to create an entity. function declarations are syntax
What is a role?
describes how we use entities. an ordinary function can play the role real function or method or constructor
What are the two reasons that arrow functions were added to JS?
cleaner/more concise syntax for creating functions
- no function keyword
- no parentheses if no parameter
- body can be a code block or an expression
they work better as real functions in methods bc of lexical this
What does this do
Lets us access the receiver.. the object that the method was called on.
What is a callback?
a callback is a function that gets passed as an argument to another function and is called asynchronously
What is spread syntax?
const obj = {1,2,3}
console.log(…obj)
> 1,2,3
destructures values of iterable objects
How is calling a function with .call() different than normal call syntax?
.call lets you specify this value.. aka it makes this go from implicit to explicit