JS 4.2 Functions Flashcards
Define “function”
also called (a function declaration or function statement) it takes input and then returns an output. Functions consist of the function keyword, followed by the name, parameters, and then JS statements that define the function in a block of code.
How do you call a function?
Type the function name, followed by parenthesis with a semi colon on the end.
Define “return” statement
The return statement ends function execution and specifies a value to be returned to the function.
Define “Parameter”
A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions.
Define “Argument”
An argument is a value(primitive or object) passed as input to a function.
How do you pass multiple arguments?
By separating each argument passed with a comma
If we call a function expression before it’s defined, what will happen and why?
I’ll get an error because only function declarations are read by the engine first, everything else has to wait until it gets to that line of code.
What is the shorthand method for arrow functions with a single parameter?
Omitting the parenthesis and declaring one single parameter.
What happens if an arrow function expression has no parameters?
Add empty parathesis
What can be omitted in an arrow function if all the code can be placed on a single line?
The ( return ) keyword. And curly braces.
If we want to pass one argument to a parameter that accepts two, what must we do to the other?
Pass the ( undefined ) keyword
Define the “throw” statement
The ( throw ) statement throws a user-defined exception. Execution of the current function will stop.
Define an “Error” object
( Error ) objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions.
If an ( arrow function ) requires addition ‘multiple’ lines of processing what MUST we now add?
We reintroduce the ( return ) keyword and add curly braces
What happens to NAMED arrow functions?
Named ( arrow functions ) are treated like variables ex: let bob = a => a + 100;