Functions Flashcards

1
Q

What is an arrow function?

A

It is something like this,

let func = (arg1, arg2, …, argN) => expression;

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

what is the arrow function of this

let sum = function(a, b) {
  return a + b;
};
A

It arrow (or shorter version is this)

let sum = (a, b) => a + b;

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

Rewrite this with arrow function.

function ask(question, yes, no) {
  if (confirm(question)) yes();
  else no();
}
ask(
  "Do you agree?",
  function() { alert("You agreed."); },
  function() { alert("You canceled the execution."); }
);
A
function ask(question, yes, no) {
  if (confirm(question)) yes();
  else no();
}
ask(
  "Do you agree?",
  () => alert("You agreed."),
  () => alert("You canceled the execution.")
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a function expression?

A

It is a function that allow us to create a function in the middle of an expression.
for example:

let sayHi = function() {
  alert( "Hello" );
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a function?

A
  • is a simple set of instruction
  • reusable
  • perform one action
  • basic building blocs of a program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Functions have 2 specific things

A

-function declaration:

function name(parameters){
body
}

-function call:

name(arguments)

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

what is the point of having function with parameters?

A

It is because different arguments can be passed into the function with a function call and can be changed every time

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

Does an arrow function need a return?

A

No arrow functions have implicit returns ( they return the value without having to type return)

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