JS 4.2 Functions Flashcards

1
Q

Define “function”

A

also called (a function declaration or function statement) it takes input and then returns an output. Functions consist of the function keyword, followed by the name, parameters, and then JS statements that define the function in a block of code.

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

How do you call a function?

A

Type the function name, followed by parenthesis with a semi colon on the end.

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

Define “return” statement

A

The return statement ends function execution and specifies a value to be returned to the function.

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

Define “Parameter”

A

A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions.

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

Define “Argument”

A

An argument is a value(primitive or object) passed as input to a function.

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

How do you pass multiple arguments?

A

By separating each argument passed with a comma

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

If we call a function expression before it’s defined, what will happen and why?

A

I’ll get an error because only function declarations are read by the engine first, everything else has to wait until it gets to that line of code.

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

What is the shorthand method for arrow functions with a single parameter?

A

Omitting the parenthesis and declaring one single parameter.

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

What happens if an arrow function expression has no parameters?

A

Add empty parathesis

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

What can be omitted in an arrow function if all the code can be placed on a single line?

A

The ( return ) keyword. And curly braces.

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

If we want to pass one argument to a parameter that accepts two, what must we do to the other?

A

Pass the ( undefined ) keyword

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

Define the “throw” statement

A

The ( throw ) statement throws a user-defined exception. Execution of the current function will stop.

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

Define an “Error” object

A

( Error ) objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions.

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

If an ( arrow function ) requires addition ‘multiple’ lines of processing what MUST we now add?

A

We reintroduce the ( return ) keyword and add curly braces

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

What happens to NAMED arrow functions?

A

Named ( arrow functions ) are treated like variables ex: let bob = a => a + 100;

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