Functions Flashcards

1
Q

What is a function in JavaScript?

A

Functions allow you to package up code for use later in your program. Block of code you can run over and over.

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

Function keyword, an optional name
zero or more parameters, a code block,
and an optional return statement

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

name of the function followed by parentheses.

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

Function call has arguments vs function definition have parameters.

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

Parameters are like placeholders for variables whose value is not known. Arguments are the values that are passed through the parameters and calling the function.

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

Why are function parameters useful?

A

Allows a function to perform tasks without knowing the specific input values ahead of time. Flexibility.

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
  1. Causes the function to produce a value we can use in our program.
  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