javascript-functions Flashcards

1
Q

What is a function in JavaScript?

A

A function in javascript is a reusable storage for blocks of code.

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 function name, parentheses that hosts the parameters, parameters, opening and closing curly braces for the block of code.

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 function name, arguments that goes inside of parentheses after the function name.

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

A function call returns the value of the function and the argument passed and causes the function to run. A function declaration is just an object holding a reusable block of code till it’s called.

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 variable that substitutes when the function is being defined while the argument is the real value passed when the function is called

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

Why are function parameters useful?

A

You can think of a parameter as a placeholder. It is basically a variable whose value is not known until we call the function and pass an argument. When the function’s code block is run, the parameter will be holding the value of the argument

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

Exits the code block once it runs so other lines after it will NOT be evaluated, Causes the function to produce a value we can use in our program.

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