javascript-functions Flashcards

1
Q

What is a function in JavaScript?

A

A function is a block of code that allows for code reusability, makes code easier to read, and makes coding “dynamic” as well as DRY.

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

The parts of a function definition are: function name (*parameter1, *parameter2) { return result or value; }

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

The parts of a function call are: function name (*arg1, *arg2);

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

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

A

The differences between a function call and a function definition are: a function definition makes an object with code that is awaiting runtime, a function call is taking a function object and running the code inside it. A function call used arguments and a function definition used parameters. A function call returns a value and is an expression.

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

What is the difference between a parameter and an argument?

A

A parameter is a placeholder for the future value of the argument being passed to that function. A function call uses arguments and a function definition uses parameters.

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

Why are function parameters useful?

A

Function parameters allow data to enter the scope and block of code within the function, be manipulated or stored, and returned. It allows one block of code to be slightly varied depending on the argument passed in.

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

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

A

Two effects a return statement has on the behavior of a function are: it instantaneously exits that function and does not run any code after the return it also gives whatever value was put after the return to the location that called the function.

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