Functions JS fill in the blank Flashcards

1
Q

A function in JavaScript is a block of code that is defined once and can be executed many times when it is ____ or ____.

A

invoked, called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Functions in JavaScript can be categorized into several types such as named, anonymous, and ____ functions, as well as ____ functions.

A

recursive, IIFEs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Closures are important in JavaScript because they establish context for code execution and are key to ____ programming and ____ functions.

A

asynchronous, generator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In JavaScript, functions can be treated as values and can be passed to other functions or ____ from other functions, demonstrating their ____ nature.

A

returned, first-class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To change the value of the ‘this’ keyword in JavaScript, you can use methods like apply, call, and ____. These methods are essential for ____ functions.

A

bind, higher order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When defining a function in JavaScript, it can be done as a declaration or an ____, and it is invoked using ____.

A

expression, parentheses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Higher order functions in JavaScript can receive functions as arguments or ____ functions, showcasing their flexibility and ____ capabilities.

A

return, functional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Generator functions and iterators in JavaScript are used for ____ over values, making them essential for ____ programming.

A

iterating, asynchronous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The main types of functions in JavaScript include named, anonymous, recursive, inner, outer, and ____. Each serves a different ____ in programming.

A

IIFEs, purpose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In JavaScript, a function is defined using the ____ keyword followed by the ____ name.

A

function, function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The executable code block of a function is contained within ____ braces and may return a value using the ____ keyword.

A

curly, return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

To invoke a function in JavaScript, you must use ____ after the function name and can pass values by including them in the ____ .

A

parentheses, parentheses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Functions in JavaScript can be treated as ____ because they can be passed around like ____ values.

A

values, primitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When defining a function, the function name is followed by parentheses which can include ____ to be passed into the function.

A

arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The ‘sum’ function takes two parameters, ____ and ____, and returns their ____ .

A

num1, num2, sum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

To change the context of a function, you can use methods like ____, ____, or ____ .

A

call, apply, bind

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In JavaScript, the most common way to define a function is through a function ____ .

A

declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The return value of a function can be captured in a variable by assigning it to a ____ .

A

let, const, var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The output of the ‘sum’ function when called with 20 and 30 is ____ .

A

50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

A function can be ____ to a variable similar to a ____ value.

A

assigned, primitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

A function can be stored in an ____ similar to a ____ value.

A

array, primitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

A function can be passed to another function as an ____ and may also be ____ from a function.

A

argument, returned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

In JavaScript, functions are treated like any other ____ because they are first class ____.

A

value, functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A named function is created by providing a name after the function ____ keyword.

A

declaration, function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

An anonymous function is defined inside a larger ____ and may not have a ____ name.

A

expression, specific

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

A recursive function calls itself as a part of the executing ____ code.

A

block, function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

In the example, the function ‘sum’ is invoked by getting the ____ element in the array.

A

third

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

The output of the function ‘sum’ when called with 20 and 30 is ____ .

A

50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Different types of functions in JavaScript depend on how they are ____ .

A

used, defined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

In JavaScript, an ____ function is defined within the code block of another function, while an ____ function is the outer function.

A

inner, outer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

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.

A

IIFE, function expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

The ‘fib’ function in the example is an example of a ____ function, while the function defined as ‘num3’ is an ____ function.

A

outer, anonymous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

In the provided example, the greeting is displayed after a delay of ____ milliseconds, and it uses a ____ function to update the HTML content.

A

1000, setTimeout

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

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.

A

expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

The ‘greeting’ function takes a parameter named ____, and it uses a template literal to create a greeting message that includes this ____.

A

name, name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

In JavaScript, functions can be ____ which means one function can be defined inside another function, allowing for more complex behavior.

A

nested

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

The output of the ‘fib’ function when called with arguments 0 and 1 is an array containing the values ____.

A

0, 1, 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

In recursion, a function calls itself to solve a problem, and it requires a specific ____ to avoid infinite loops.

A

exit condition, base case

39
Q

The Fibonacci sequence starts with 0 and 1, and each number is the sum of the previous ____ numbers.

A

two, numbers

40
Q

An infinite recursion occurs when a recursive function lacks an ____ condition, leading to an infinite loop.

A

exit, base

41
Q

Arrow functions provide a more ____ syntax compared to traditional function expressions in JavaScript.

A

compact, concise

42
Q

In the Fibonacci function, if the sequence length is greater than or equal to the specified length, it will ____ the sequence.

A

return, output

43
Q

The error thrown by JavaScript when maximum call stack size is exceeded is called a ____ error.

A

RangeError, stack overflow

44
Q

To compute the Fibonacci sequence, the function uses the last two numbers in the sequence to calculate the ____ number.

A

next, subsequent

45
Q

The function ‘multiply’ demonstrates an infinite recursion by calling itself without a proper ____ condition.

A

exit, termination

46
Q

In the example of infinite recursion, the function ‘multiply’ uses the method ____ to remove the last element from the array.

A

pop, shift

47
Q

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.

A

removed, implied

48
Q

The arrow function version of a function can omit the ____ if it has a single statement, and the ____ keyword can also be omitted.

A

braces, return

49
Q

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.

A

invoked, context

50
Q

When defining an arrow function without parameters, you must use an empty set of ____ to indicate that there are no parameters.

A

parentheses

51
Q

The arrow function version of the greeting function can be written as name => console.log(Good Morning \_\_\_\_ !);, where ____ is the parameter name.

A

{name}, name

52
Q

In the arrow function version of the sum function, the syntax is num1, num2 => num1 ____ num2; where the operator is ____ .

53
Q

In the random function example, if the generated number is greater than 5, the return value is ____; otherwise, it returns the ____ .

54
Q

The arrow function version of the random function uses an implicit return when there is a single ____ statement.

A

expression

55
Q

In JavaScript, the this keyword in arrow functions does not default to the ____ object, unlike traditional functions.

56
Q

In JavaScript, if ‘this’ is not set by the call, it defaults to the _____ object and can refer to _____ in a method.

A

global, the object itself

57
Q

When calling ‘sayHeight’ from the person object, ‘this’ refers to the _____, while calling ‘sayWeight’ results in ‘this’ being the _____ object.

A

person, global

58
Q

A higher-order function can either receive a function as an _____ or return a function as a _____ value.

A

argument, return

59
Q

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 _____.

A

function, array

60
Q

In the example of ‘createMultiplyFunction’, it returns a function that multiplies its input by a given _____, demonstrating the concept of _____ functions.

A

number, higher-order

61
Q

A function passed into another function is known as a _____ function, which is essential for _____ coding in JavaScript.

A

callback, asynchronous

62
Q

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.

63
Q

When ‘showDate’ is called, it logs the values of ‘_____ ‘ and ‘_____ ‘ to the console, demonstrating the use of event listeners.

A

intro, date

64
Q

The output of ‘multiplyBy10(5)’ is _____, showing how a function can be returned and used later in JavaScript.

65
Q

In the context of asynchronous functions, the ‘addEventListener’ method allows for _____ execution of code when an event occurs.

A

non-blocking

66
Q

In JavaScript, synchronous code runs in a ____ manner, while asynchronous code operates ____ the normal sequence of execution.

A

synchronous, outside

67
Q

Function declarations in JavaScript are ____ which means they can be invoked before they are ____ in the code.

A

hoisted, defined

68
Q

Closure in JavaScript allows a function to access its ____ scope even after the function that created the parent scope has ____ execution.

A

parent, completed

69
Q

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.

A

clicked, the event

70
Q

When a function expression is invoked before it is defined, it results in a ____ error, while a function declaration does not.

A

ReferenceError

71
Q

In the example of closure, the ‘createScoreFunction’ returns a function that adds to the ____ array and then prints the number of ____.

A

scores, values

72
Q

JavaScript code runs to completion without stopping in a ____ manner, while asynchronous code allows for ____ operations.

A

synchronous, non-blocking

73
Q

The main difference between function declarations and function expressions is that function declarations are ____ and can be invoked at any time.

74
Q

The apply() method invokes a function and passes in the arguments as a _____, while the call() method passes them as a _____.

A

array, comma separated list

75
Q

In JavaScript, the bind() method returns a new function and assigns the object passed in to the keyword ‘this’, allowing for _____ and _____ of arguments.

A

binding, passing

76
Q

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 _____.

A

function, comma separated list

77
Q

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.

A

firstName, punct

78
Q

The createScoreFunction returns a function that can access the scores array through _____, allowing it to modify the _____ of scores.

A

closure, length

79
Q

The output of addScore(70) shows that the total scores is now _____, while addScore(90) increases it to _____.

80
Q

In the example provided, objGreet.morningGreet.call(user1, ‘!’) demonstrates the use of _____ to invoke a function with a specific context.

81
Q

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.

82
Q

The generator function is defined with an asterisk (*) and is used to create a _____ that can yield multiple values over time.

83
Q

The eveningGreet function in objGreet uses the keyword ‘this’ to refer to the _____ of the user object passed in.

84
Q

A generator function is defined with an asterisk (*) and can be used with the ____ method to iterate over ____ values.

A

next(), values

85
Q

The yield keyword is used in a generator function to ____ the function and return the ____ in the current iteration.

A

pause, value

86
Q

In the fibonacci sequence generator, the first two numbers are ____ and ____ before generating the next numbers.

87
Q

The next() method returns an object with properties ‘value’ and ____ which indicates if there are more values to return.

88
Q

When there are no more values left to return, the ‘done’ property becomes ____ and the value returned is ____ .

A

true, undefined

89
Q

An iterator is a special object that implements a ____ sequence for a collection of ____ .

A

one-at-a-time, items

90
Q

In the progressive factorial example, each time next() is used, a new ____ and its ____ are displayed.

A

number, factorial

91
Q

The fibonacci sequence generator produces a sequence of ____ numbers, with each new number being added ____ at a time.

92
Q

The output of the fibonacci sequence generator is an array that contains the ____ of the sequence generated so far.

93
Q

The rhymeGenerator function yields several lines including ‘One, two, three, four, five,’ and ‘____ I caught a fish alive.’