JavaScript: Functions Flashcards

1
Q

What are functions?

A

Functions are reusable blocks of code that perform a specific task.

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

What is a function declaration?
What is the syntax?

A

function declareHello() {
console.log(“Hello, I am a function declaration.”);
console.log(“———————————–”);
return;

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

What is a function expression?
What is the syntax?

A

const expressHello = function () {
console.log(“Hello, I am a function expression.”);
console.log(“———————————–”);
return;
};

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

How do you execute a function?
What is the syntax?

A

Functions must be called to execute

Example:

// Function
function declareHello() {
console.log(“Hello, I am a function declaration.”);
console.log(“———————————–”);
return;

//Function call
declareHello();

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

What are function parameters?

A

Parameters give a name to the data to be passed into the function.

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

What is the syntax for function parameters?
What are function arguments?

A

function declareHelloAgain(x, y, z, d, f) {
console.log(
Hello, the values of my parameters are ${x}, ${y}, ${z}, ${d}, ${f}.
);
console.log(“———————————–”);
return;

// Function arguments give parameters their values
// Here the parameter x is given the value 7 when the function is called
declareHelloAgain(7, “Hello”, true, dog, cat);

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