JS Functions Flashcards
What is a function in JavaScript?
A function is a special kind of object that is “callable”.
It is a group of actions that are repeatable.
Describe the parts of a function definition.
A function definition has the keyword function, followed by a name (optional), parentheses ( ), and curly braces { }. Within the ( ) are parameters (optional). Within { } is the code block, which might include a return statement (optional).
Describe the parts of a function call.
A function call has the name of the function, followed by parentheses ( ). Within the parentheses are arguments.
What two effects does a return statement have on the behavior of a function?
1) Causes the function to produce a value we can use in our program; saves the value
2) Prevents any more code in the function’s code block from being run.
Why are function parameters useful?
Parameters give variability to the function.
They serve as placeholders for variables whose value is unknown until the function is called to pass an argument.
What is the difference between a parameter and an argument?
Parameters are declared when defining a function; have no value and receives a value when a function is called.
Arguments are passed when calling a function
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition: has the keyword ‘function’, has curly brackets { } with a code block nested within the brackets.
Function call: simply has the name of the function, followed by parentheses ( ).
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
Defined
What allows JavaScript functions to “remember” values from their surroundings?
Closures
What must the return value ofmyFunctionbe if the following expression is possible? myFunction()();
Must return a function
What does this code do? const wrap = value => () => value;
Const wrap = function (value) { function () { return value } }