Functions Flashcards

1
Q

Function

A

function showMessage() {
alert( ‘Hello everyone!’ );
}

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

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

Function is a value

A

let sayHi = function() {
alert( “Hello” );
};

In JavaScript, a function is a value, so we can deal with it as a value. The code above shows its string representation, which is the source code.
A function is a special value, in the sense that we can call it like sayHi().
Regular values like strings or numbers represent the data.
A function can be perceived as an action.

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

Semicolon at end

A

The semicolon would be there for a simpler assignment, such as let sayHi = 5;, and it’s also there for a function assignment.

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

Arrow Functions

A

Simpler form than function expressions
let sum = (a, b) => a + b;

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

Multiline Arrow Functions

A

let sum = (a, b) => { // the curly brace opens a multiline function
let result = a + b;
return result; // if we use curly braces, then we need an explicit “return”
};

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