JS week 1 day 2 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
Describe the parts of a function definition.
function keyword, optional name, 0 or more parameters separated by commas surround by parentheses, opening curly brace, optional return statement, closing curly brace.
Describe the parts of a function call.
function’s name, 0 or more arguments separated by commas surrounded by parentheses.
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition only defines a function and calling the function returns the result of task written inside of the function.
What is the difference between a parameter and an argument?
parameter is a placeholder, argument is the actual value that is passed into the function.
Why are function parameters useful?
parameters make the function reusable.
What two effects does a return statement have on the behavior of a function?
- Causes the function to produce a value we can use in our program.
- Prevents any more code in the function’s code block from being run.