JavaScript Functions Flashcards

(15 cards)

1
Q

How is a function declared and called?

A

function keyword > function identifier () {
console.log (‘Water the plants.’);
}

function functionname () {
console.log (‘Water the plants.’);
}

it’s called using the below.

functionname();

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

What are function parameters and how are they declared?

A

Function parameters are basically variables.

The parameters are defined in the parenthesis when declaring the functions.

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

What is an argument?

A

Values passed to a function when said function is called.

Example
rectangleArea(5,10);

you can pass an argument as a value or create a variable with a value and then pass the variable as an argument.

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

How is a default parameter value created and then an argument value passed to overwrite the default value.

A

Assign the parameter a value in the parenthesis to create a default value.

When calling the function provide a value to overwrite the default.

function greeting (name = ‘stranger’) {
console.log(Hello, ${name}!)
}

greeting (Hassam);

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

What is the purpose of the return keyword with in a function?

A

To pass back information from the function, without the keyword JavaScript will calculate but not store the value.

Without the return keyword any value called outside the function will have a value of undefined.

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

Does using the return keyword stop the execution of code?

A

Yes any code after the return keyword within a functions body will stop all code below from running.

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

What is a helper function and it’s benefits?

A

A function within a function, the purpose is for one function to call another to get a return value.

Makes the code easier to read and debug. Breaking down larger difficult code into smaller manageable chunks.

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

How do you assign a function value to a variable.

A

function costOfMonitors(rows, columns) {
return monitorCount(rows, columns) * 200;
}

const totalCost = costOfMonitors(5, 4);

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

Function Declaration vs Function Expression?

A

Declaration - A declared function that requires a name.

Expression - Often created with a variable and doesn’t need name, called a anonymous function.

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

How is a function expression written?

A

const sizeConversion = function(width, height) {
const area = width * height;
return area;
};

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

How is a function expression written using a fat arrow notation (Arrow function)?

A

const sizeConversion = (width, height) => { const area = width * height;
return area;
};

Writing an function expression without the function keyword.

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

The most condensed form of the function is known as a?

A

Concise body, refactored using arrow functions.

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

How are parameters written when using arrow functions?

A

Zero parameters requires parenthesis ().
One parameters require no parenthesis.
More than one parameter requires parenthesis().

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

What is an Implicit Return?

A

To return a function value the return keyword isn’t needed when when using a function expression alongside arrow notation. The function also needs to be written in a single line.

SINGLE-LINE-BLOCK
const sumNumbers = number => number + number;

MULTI-LINE-BLOCK
const sumNumbers = number => {
const sum = number + number;
return sum; «RETURN STATEMENT
}

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

Why would a function pass undefined when logged to the console?

A

A function without a return will pass back undefined.

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