javascript-functions Flashcards

1
Q

What is a function in JavaScript?

A

Functions allow you to package up code for use later in your program; collection of code we can call any time we like and pass in values

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
  1. Function keyword
  2. Optional name
  3. Comma separated list of zero or more arguments surrounded by parentheses
  4. Code block
  5. 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
  1. Function name

2. Comma separated list of zero or more arguments surrounded 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

Definition has the function keyword and code block (as seen by the curly braces)

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

When we define a function, we declare parameters (like a placeholder) and when we call a function, we pass it arguments (actual values)

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

Why are function parameters useful?

A

They work as placeholders for values that are not known until it can later be used to pass in any value into a function

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