Functions Flashcards
What is a function?
a function is a procedure that lets you extract code and run it as a separate unit
what is a function name without parentheses?
Without parentheses a function like funcName() is not a function call but simply the name of the function. The value being a function object representing the function in question
what scope do parameters have?
Parameters arelocal variablesonly available within the function’s body
What happens when you nest a function in another function?
These are private functions which can only be called within the parent functions definition.
What scope do function names have?
Function names are either global or local, depending on whether the function is at the program’s top level or nested inside a class, object, or another function.
What are arguments?
Arguments are objects or primitive values passed to a function
What are parameters?
parameters are declarations for the local variables used inside the function to access the arguments.
What happens if you provide too few/too many arguments?
If you provide too few arguments, the parameters and variables that correspond to the missing arguments will receive a value ofundefined. Additional arguments will be ignored if you provide too many
What is a function which only returns a boolean called?
A predicate
What is the implicit return value of most JS functions?
Undefined
What is an explicit return value?
An explicit return value is when you provide an specific overriding return in the function definition
how do you define default parameters?
function say(text = “hello”) {
console.log(text + “!”);
}
How is a method different than a function? How can we tell the difference?
Methods are functions built into existing objects. We can tell because they use a period for invocation. ‘xyzzy’.toUpperCase()
What’s the difference between reassignment and mutation?
To change a variable can either change what value is assigned (orbound) to a variable or we can change the value of the thing that is bound to the variable. The former is known asreassignmentwhile the latter is known asmutation.
Can we change primitives?
No. Primitive values are immutable.