functions Flashcards

1
Q

What is a function in JavaScript?

A

a tool that allows you to package up code for later use.

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

Describe the parts of a functiondefinition.

A

function keyword, optional name, 0 or more parameters , a code block, 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 functioncall.

A

functions name, a comma separated list of arguments.

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 functioncalland a functiondefinition?

A

functions are called with arguments, functions are defined with parameters.

when defining a function, parameters are declared, when we call a function, we pass as arguments.

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

What is the difference between aparameterand anargument?

A

arguments are values given to function.

parameters are local variables that we can access from outside the function.

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

Why are functionparametersuseful?

A

parameter is like a placeholder that when the function’s code block is run, the parameter will be given the value of the argument. allows to locally store information that function can use

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

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

A

causes the function to produce a value that we can use
prevents any more code in the function’s code block from being run
exits function’s code block

variables are scoped— available in certain places all functions can access global variables
parameters are local variable to function- in accessible from outside of the function.

function syntax:

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