FUNCTIONS Flashcards

1
Q

What is a function declaration ?

A

Is a function that is bound to an identifier, or name.

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

What is the anatomy of a function declaration?

A
  • The function keyword.
  • The name of the function, or its identifier, followed by parentheses.
  • A function body, or the block of statements required to perform a specific task, enclosed in the function’s curly brackets, { }.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to call a function ?

A

Functions can be called, or executed, elsewhere in code using parentheses following the function name. When a function is called, the code inside its function body runs. Arguments are values passed into a function when it is called.

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

How do we call the input when we declare a function ?

A

Parameters

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

What does parameters in a function?

A

Parameters allow functions to accept input(s) and perform a task using the input(s).
We use parameters as placeholders for information that will be passed to the function when it is called.

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

What to do when we are calling a function that has parameters?

A

We specify the values in the parentheses that follow the function name.

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

What do we call the values that are passed to the function?

A

The values that are passed to the function when it is called are called arguments. Arguments can be passed to the function as values or variables.

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

How to print the result of the function (with parameters)?

A

You need to use the keyword return.
> Also called : a return statement
Otherwise, the computer is going to calculate (or something else) but not capture it.

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

How to create a return statement?

A

> We use the return keyword followed by the value that we wish to return.
The return keyword is powerful because it allows functions to produce an output. We can then save the output to a variable for later use.

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

What is a helper functions ?

A

We can also use the return value of a function inside another function. These functions being called within another function are often referred to as helper functions. Since each function is carrying out a specific task, it makes our code easier to read and debug if necessary.

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

What is another way to define a function ?

A

Another way to define a function is to use a function expression.

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

How is called a function with no name?

A

A function with no name is called an anonymous function.

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

How to invoke a function expression?

A

Write the name of the variable in which the function is stored followed by parentheses enclosing any arguments being passed into the function.

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

What is different for the function expressions compared to function declarations?

A

Unlike function declarations, function expressions are not hoisted so they cannot be called before they are defined.

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