Functions Flashcards
What is a general definition of a function?
A function is a block of code that executes tasks in a specific order.
How do you declare a function in JavaScript
function [functionName] (parameters) {
[workingCode]
}
What are parameters of a function?
Parameters are optional, comma separated variables that you wish to declare for the function.
These parameters can be assigned values when you use the function.
How can you use a function?
You can use a function by calling (evoking, executing) it with its name and the brackets that surround any parameters (even if there are no parameters).
functionName(parameters)
When do parameters become arguments in functions execution.
Parameters become arguments when we give actual values during a function execution.
What is the difference between parameters and arguments when using functions?
Parameters - variables used when declaring a function.
Arguments - values used in place of parameters when invoking a function.
What is the result of defining a parameter in a function but not passing in an argument during execution
The result is that the parameter value will be ‘undefined’.
What is returned from a function if a return statement is not included in the code block?
Undefined is returned
What types of values can JavaScript pass around?
JavaScript can pass Primitives and Objects.
Expressions need to be evaluated to either of these two values before being passed.
What happens if you pass a function with parameters as an argument to another function?
The function argument needs to be evaluated before being used in the calling function (in this case it is an expression)
What is the term for a function (without parameters) that is passed as an argument to another function.
In this case the function is a callback (because you call-it-back within the code-block of the calling function).
What is function hoisting in JavaScript.
Function hoisting is when function declarations are moved to the top of the scope regardless of their place in the code.
Should we rely on function hoisting?
No, we should always declare our functions before invoking them.
What is a function expression?
A function expression is when a variable is defined using an anonymous function.
Are function expressions hoisted?
No, variables defined with a function are not hoisted in the scope.
What is the syntax of an arrow function?
(param1, param2) => { code-block }