javascript-functions Flashcards
What is a function in JavaScript?
A function in javascript is a reusable storage for blocks of code.
Describe the parts of a function definition.
function keyword, optional function name, parentheses that hosts the parameters, parameters, opening and closing curly braces for the block of code.
Describe the parts of a function call.
the function name, arguments that goes inside of parentheses after the function name.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call returns the value of the function and the argument passed and causes the function to run. A function declaration is just an object holding a reusable block of code till it’s called.
What is the difference between a parameter and an argument?
A parameter is a placeholder variable that substitutes when the function is being defined while the argument is the real value passed when the function is called
Why are function parameters useful?
You can think of a parameter as a placeholder. It is basically a variable whose value is not known until we call the function and pass an argument. When the function’s code block is run, the parameter will be holding the value of the argument
What two effects does a return statement have on the behavior of a function?
Exits the code block once it runs so other lines after it will NOT be evaluated, Causes the function to produce a value we can use in our program.