JavaScript Functions Flashcards

1
Q

What are functions?

A

Reusable blocks of code

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

Write an example of a function declaration

A
function greetWorld() {
    console.log('Hello, World!);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write an example of a function expression

A
const calculateArea = function(width, height) {
    const area = width * height;
    return area;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write an example of an arrow function

A
const calculateArea = (width, height) => {
    const area = width * height;
    return area;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Using arrow notation, write an example of a function with a single-line block of code and multi-line block of code

A
Single-Line Block
const sumNumbers = number => number + number;
Multi-Line Block
const sumNumbers = number => {
    const sum = number + number;
    return sum;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly