JS week 1 day 2 Flashcards

1
Q

What is a function in JavaScript?

A

A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value

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, optional name, 0 or more parameters separated by commas surround by parentheses, opening curly brace, optional return statement, closing curly brace.

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

function’s name, 0 or more arguments separated by commas 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

function definition only defines a function and calling the function returns the result of task written inside of the function.

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

parameter is a placeholder, argument is the actual value that is passed into 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

parameters make the function reusable.

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