3 - Functions Flashcards
What purposes do functions serve?
- reduce repetition
- enable naming concepts (abstractions)
- isolate code
- design and sturcture programs
What is a function definition?
A binding that references a function value.
What construct enables a function to receive input?
Parameters.
What is a function argument?
Value that is bind to a function parameter when the function is called.
What is a function body?
Block of code which wraps code of a function.
How many params can a function have?
There is no limit on the number of params function can take.
What happens when function defines one param, but is passed two?
Additional parameters are ignored.
Why can’t a function be called with more parameters then the amount of the ones you define?
It can.
When you invoke a function with lesser number of arguments than those defined, what happens?
Params which don’t receive a value on invocation are assigned ‘undefined’.
What is the minimal number of arguments you can define a function with?
Zero.
What are the ways to define a function?
- function foo() {}
- const foo = function() {}
- const foo = () => {}
For which two things you use functions for?
- return a value
- side effect
What keyword do you use inside a function to return a value?
‘return’
What is the return value when there is no ‘return’ statement in the function?
‘undefined’
What happens when you return two values in a list ‘return 1, 2;’?
Returned value is ‘2’.
What is the anatomy of a function?
- might have ‘function’ keyword
- name of a function
- parameters
- body