javascript-functions Flashcards
What is a function in JavaScript?
A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.
Describe the parts of a function definition
A function has three parts, a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements of the set of outputs in such a way that each input is assigned exactly one output.
Describe the parts of a function call.
The function keyword. An optional name ( this is also because it can be anonymous ). A list of parameters names enclosed in parentheses. The statement enclosed in braces.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function expression is very similar to and has almost the same syntax as a function declaration (see function statement for details). The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions.
What is the difference between a parameter and an argument?
Note the difference between parameters and arguments: Function parameters are the names listed in the function’s definition. Function arguments are the real values passed to the function. Parameters are initialized to the values of the arguments supplied.
Why are function parameters useful?
A function can take parameters which are just values you supply to the function so that the function can do something utilising those values.
What two effects does a return statement have on the behavior of a function?
A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.