Functions Flashcards
What are functions?
A JavaScript procedure.
A set of statements that performs a task or calculates a value.
How can you use a function?
You have to define it somewhere in the scope from which you want to call it.
A function consists of the function keyword, followed by __________. ________ enclosed in parentheses, and the _______ enclosed in curly brakets.
the function name.
Parameters.
statements.
What are Function Expressions?
A function without a name. It is an anonymous function.
A function expression can have a name inside the function to what?
refer to itself
When are function expressions convenient over function declarations?
When passing a function as an argument to another function.
What are the three ways for a function to refer to itself?
- the function’s name
- arguments.callee
- An in-scope variable that refers to the function
What are the two kinds of parameters in functions?
- Default parameters
2. Rest parameters
What is the default parameter for functions?
Undefined
How can you change the default parameter?
By assigning a value to the argument name.
eg.)
function hello (a, b = 1) { }
The default value is now 1 and not undefined.
What is the rest parameter?
Allows us to represent an indefinite number of arguments as an array.
An arrow function expression lexically binds the ____ value.
this
Are arrow functions always anonymous?
Yes
What are the two factors influenced the introduction of arrow functions?
Short functions and lexical ‘this’
What is the syntax for an function expression?
functionName( => code block );