Functions Flashcards

1
Q

Explain a function

A

A function is simply a piece of reusable code.

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

What are the three types of functions in JS?

A
  • Function declaration
  • Function expression(Anonymous function)
  • Arrow function(ES6)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write down a function declaration in JS.

A
function calcAge(currentYear, birthYear) {
    return currentYear - birthYear;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the differences between function declarations, function expressions & arrow functions in JS?

A
  • Function declarations can be invoked before they are defined as a result of a process called hoisting.(It allows hoisting).
  • A function expression is basically a function stored in a variable.
  • An arrow function is a special type of function expression that is shorter, introduced in ES6. The arrow function does not have the “this” keyword.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write down a function declaration in JS.

A
function calcAge(currentYear, birthYear) {
    return currentYear - birthYear;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write down a Function expression in JS?

A
const calcAge = function (currentYear, birthYear) {
    return currentYear - birthYear;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write down an arrow function.

A

const calcAge =(currentYear, birthYear) => currentYear - birthYear;

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