Functions JS fill in the blank Flashcards
A function in JavaScript is a block of code that is defined once and can be executed many times when it is ____ or ____.
invoked, called
Functions in JavaScript can be categorized into several types such as named, anonymous, and ____ functions, as well as ____ functions.
recursive, IIFEs
Closures are important in JavaScript because they establish context for code execution and are key to ____ programming and ____ functions.
asynchronous, generator
In JavaScript, functions can be treated as values and can be passed to other functions or ____ from other functions, demonstrating their ____ nature.
returned, first-class
To change the value of the ‘this’ keyword in JavaScript, you can use methods like apply, call, and ____. These methods are essential for ____ functions.
bind, higher order
When defining a function in JavaScript, it can be done as a declaration or an ____, and it is invoked using ____.
expression, parentheses
Higher order functions in JavaScript can receive functions as arguments or ____ functions, showcasing their flexibility and ____ capabilities.
return, functional
Generator functions and iterators in JavaScript are used for ____ over values, making them essential for ____ programming.
iterating, asynchronous
The main types of functions in JavaScript include named, anonymous, recursive, inner, outer, and ____. Each serves a different ____ in programming.
IIFEs, purpose
In JavaScript, a function is defined using the ____ keyword followed by the ____ name.
function, function
The executable code block of a function is contained within ____ braces and may return a value using the ____ keyword.
curly, return
To invoke a function in JavaScript, you must use ____ after the function name and can pass values by including them in the ____ .
parentheses, parentheses
Functions in JavaScript can be treated as ____ because they can be passed around like ____ values.
values, primitive
When defining a function, the function name is followed by parentheses which can include ____ to be passed into the function.
arguments
The ‘sum’ function takes two parameters, ____ and ____, and returns their ____ .
num1, num2, sum
To change the context of a function, you can use methods like ____, ____, or ____ .
call, apply, bind
In JavaScript, the most common way to define a function is through a function ____ .
declaration
The return value of a function can be captured in a variable by assigning it to a ____ .
let, const, var
The output of the ‘sum’ function when called with 20 and 30 is ____ .
50
A function can be ____ to a variable similar to a ____ value.
assigned, primitive
A function can be stored in an ____ similar to a ____ value.
array, primitive
A function can be passed to another function as an ____ and may also be ____ from a function.
argument, returned
In JavaScript, functions are treated like any other ____ because they are first class ____.
value, functions
A named function is created by providing a name after the function ____ keyword.
declaration, function
An anonymous function is defined inside a larger ____ and may not have a ____ name.
expression, specific
A recursive function calls itself as a part of the executing ____ code.
block, function
In the example, the function ‘sum’ is invoked by getting the ____ element in the array.
third
The output of the function ‘sum’ when called with 20 and 30 is ____ .
50
Different types of functions in JavaScript depend on how they are ____ .
used, defined
In JavaScript, an ____ function is defined within the code block of another function, while an ____ function is the outer function.
inner, outer
A function that is invoked at the same time it is defined is called an ____ (pronounced as ‘iffy’), while a function that is assigned to a variable is known as a ____ function.
IIFE, function expression
The ‘fib’ function in the example is an example of a ____ function, while the function defined as ‘num3’ is an ____ function.
outer, anonymous
In the provided example, the greeting is displayed after a delay of ____ milliseconds, and it uses a ____ function to update the HTML content.
1000, setTimeout
A function expression is similar to a function declaration, but it is used to define a function as part of an ____ rather than a standalone statement.
expression
The ‘greeting’ function takes a parameter named ____, and it uses a template literal to create a greeting message that includes this ____.
name, name
In JavaScript, functions can be ____ which means one function can be defined inside another function, allowing for more complex behavior.
nested
The output of the ‘fib’ function when called with arguments 0 and 1 is an array containing the values ____.
0, 1, 1
In recursion, a function calls itself to solve a problem, and it requires a specific ____ to avoid infinite loops.
exit condition, base case
The Fibonacci sequence starts with 0 and 1, and each number is the sum of the previous ____ numbers.
two, numbers
An infinite recursion occurs when a recursive function lacks an ____ condition, leading to an infinite loop.
exit, base
Arrow functions provide a more ____ syntax compared to traditional function expressions in JavaScript.
compact, concise
In the Fibonacci function, if the sequence length is greater than or equal to the specified length, it will ____ the sequence.
return, output
The error thrown by JavaScript when maximum call stack size is exceeded is called a ____ error.
RangeError, stack overflow
To compute the Fibonacci sequence, the function uses the last two numbers in the sequence to calculate the ____ number.
next, subsequent
The function ‘multiply’ demonstrates an infinite recursion by calling itself without a proper ____ condition.
exit, termination
In the example of infinite recursion, the function ‘multiply’ uses the method ____ to remove the last element from the array.
pop, shift
In JavaScript, when a function has a single parameter, the parentheses can be ____ and the return statement can be ____ if the body has only one statement.
removed, implied
The arrow function version of a function can omit the ____ if it has a single statement, and the ____ keyword can also be omitted.
braces, return
In traditional functions, the this keyword is set to the object that ____ the function, while in arrow functions, it is determined by the ____ of the function call.
invoked, context
When defining an arrow function without parameters, you must use an empty set of ____ to indicate that there are no parameters.
parentheses
The arrow function version of the greeting function can be written as name => console.log(Good Morning \_\_\_\_ !
);, where ____ is the parameter name.
{name}, name
In the arrow function version of the sum function, the syntax is num1, num2 => num1 ____ num2; where the operator is ____ .
+ , +
In the random function example, if the generated number is greater than 5, the return value is ____; otherwise, it returns the ____ .
0, num
The arrow function version of the random function uses an implicit return when there is a single ____ statement.
expression
In JavaScript, the this keyword in arrow functions does not default to the ____ object, unlike traditional functions.
global
In JavaScript, if ‘this’ is not set by the call, it defaults to the _____ object and can refer to _____ in a method.
global, the object itself
When calling ‘sayHeight’ from the person object, ‘this’ refers to the _____, while calling ‘sayWeight’ results in ‘this’ being the _____ object.
person, global
A higher-order function can either receive a function as an _____ or return a function as a _____ value.
argument, return
The ‘map’ method of the Array object is an example of a higher-order function because it accepts a _____ as an argument and returns a new _____.
function, array
In the example of ‘createMultiplyFunction’, it returns a function that multiplies its input by a given _____, demonstrating the concept of _____ functions.
number, higher-order
A function passed into another function is known as a _____ function, which is essential for _____ coding in JavaScript.
callback, asynchronous
In the event listener example, the ‘showDate’ function is executed when the button is clicked, allowing the program to continue running without _____ at that point.
stopping
When ‘showDate’ is called, it logs the values of ‘_____ ‘ and ‘_____ ‘ to the console, demonstrating the use of event listeners.
intro, date
The output of ‘multiplyBy10(5)’ is _____, showing how a function can be returned and used later in JavaScript.
50
In the context of asynchronous functions, the ‘addEventListener’ method allows for _____ execution of code when an event occurs.
non-blocking
In JavaScript, synchronous code runs in a ____ manner, while asynchronous code operates ____ the normal sequence of execution.
synchronous, outside
Function declarations in JavaScript are ____ which means they can be invoked before they are ____ in the code.
hoisted, defined
Closure in JavaScript allows a function to access its ____ scope even after the function that created the parent scope has ____ execution.
parent, completed
An example of asynchronous code is when an event handler is set up for a button, but it is not executed until the button is ____ and ____ is triggered.
clicked, the event
When a function expression is invoked before it is defined, it results in a ____ error, while a function declaration does not.
ReferenceError
In the example of closure, the ‘createScoreFunction’ returns a function that adds to the ____ array and then prints the number of ____.
scores, values
JavaScript code runs to completion without stopping in a ____ manner, while asynchronous code allows for ____ operations.
synchronous, non-blocking
The main difference between function declarations and function expressions is that function declarations are ____ and can be invoked at any time.
hoisted
The apply() method invokes a function and passes in the arguments as a _____, while the call() method passes them as a _____.
array, comma separated list
In JavaScript, the bind() method returns a new function and assigns the object passed in to the keyword ‘this’, allowing for _____ and _____ of arguments.
binding, passing
When using the call() method, the first argument is the object to be assigned to ‘this’, and the second argument is the _____, which is passed as a _____.
function, comma separated list
In the context of the objGreet object, the morningGreet function uses the keyword ‘this’ to access the user’s _____, while the eveningGreet function does the same for the _____ parameter.
firstName, punct
The createScoreFunction returns a function that can access the scores array through _____, allowing it to modify the _____ of scores.
closure, length
The output of addScore(70) shows that the total scores is now _____, while addScore(90) increases it to _____.
1, 2
In the example provided, objGreet.morningGreet.call(user1, ‘!’) demonstrates the use of _____ to invoke a function with a specific context.
call
The bind() method is unique because it returns a new function that can be invoked later, allowing for the _____ of parameters to be set in advance.
binding
The generator function is defined with an asterisk (*) and is used to create a _____ that can yield multiple values over time.
generator
The eveningGreet function in objGreet uses the keyword ‘this’ to refer to the _____ of the user object passed in.
firstName
A generator function is defined with an asterisk (*) and can be used with the ____ method to iterate over ____ values.
next(), values
The yield keyword is used in a generator function to ____ the function and return the ____ in the current iteration.
pause, value
In the fibonacci sequence generator, the first two numbers are ____ and ____ before generating the next numbers.
0, 1
The next() method returns an object with properties ‘value’ and ____ which indicates if there are more values to return.
done
When there are no more values left to return, the ‘done’ property becomes ____ and the value returned is ____ .
true, undefined
An iterator is a special object that implements a ____ sequence for a collection of ____ .
one-at-a-time, items
In the progressive factorial example, each time next() is used, a new ____ and its ____ are displayed.
number, factorial
The fibonacci sequence generator produces a sequence of ____ numbers, with each new number being added ____ at a time.
100, one
The output of the fibonacci sequence generator is an array that contains the ____ of the sequence generated so far.
values
The rhymeGenerator function yields several lines including ‘One, two, three, four, five,’ and ‘____ I caught a fish alive.’
Once