JS Functions Flashcards

1
Q

What is a function in JavaScript?

A

A function is a special kind of object that is “callable”.

It is a group of actions that are repeatable.

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

Describe the parts of a function definition.

A

A function definition has the keyword function, followed by a name (optional), parentheses ( ), and curly braces { }. Within the ( ) are parameters (optional). Within { } is the code block, which might include a return statement (optional).

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

Describe the parts of a function call.

A

A function call has the name of the function, followed by parentheses ( ). Within the parentheses are arguments.

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

What two effects does a return statement have on the behavior of a function?

A

1) Causes the function to produce a value we can use in our program; saves the value
2) Prevents any more code in the function’s code block from being run.

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

Why are function parameters useful?

A

Parameters give variability to the function.

They serve as placeholders for variables whose value is unknown until the function is called to pass an argument.

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

What is the difference between a parameter and an argument?

A

Parameters are declared when defining a function; have no value and receives a value when a function is called.
Arguments are passed when calling a function

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

Function definition: has the keyword ‘function’, has curly brackets { } with a code block nested within the brackets.
Function call: simply has the name of the function, followed by parentheses ( ).

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

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

Defined

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

What allows JavaScript functions to “remember” values from their surroundings?

A

Closures

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

What must the return value ofmyFunctionbe if the following expression is possible? myFunction()();

A

Must return a function

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

What does this code do? const wrap = value => () => value;

A
Const wrap = function (value) {
	function () {
		return value
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly