functions Flashcards
What is a function in JavaScript?
a tool that allows you to package up code for later use.
Describe the parts of a functiondefinition.
function keyword, optional name, 0 or more parameters , a code block, an optional return statement.
Describe the parts of a functioncall.
functions name, a comma separated list of arguments.
When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
functions are called with arguments, functions are defined with parameters.
when defining a function, parameters are declared, when we call a function, we pass as arguments.
What is the difference between aparameterand anargument?
arguments are values given to function.
parameters are local variables that we can access from outside the function.
Why are functionparametersuseful?
parameter is like a placeholder that when the function’s code block is run, the parameter will be given the value of the argument. allows to locally store information that function can use
What two effects does areturnstatement have on the behavior of a function?
causes the function to produce a value that we can use
prevents any more code in the function’s code block from being run
exits function’s code block
variables are scoped— available in certain places all functions can access global variables
parameters are local variable to function- in accessible from outside of the function.
function syntax: