Functions Flashcards

1
Q

A Function Expresssion that prints a pizza order

A
const takeOrder = () => {
  console.log('Order: pizza');
};

takeOrder();

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

What are parameters?

A

Parameters are variables in a function definition that represent data we can input into the function.

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

Function Declaration example syntax:

A
function bar() {
    return 3;
}

bar() //3
bar //function

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

Anonymous Function Expression example syntax:

A
//anonymous function expression
var a = function() {
    return 3;
}
//named function expression
var a = function bar() {
    return 3;
}
//self invoking function expression
(function sayHello() {
    alert("hello!");
})();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Refactor:
const multiplyByNineFifths = (celsius) => {
  return celsius * (9/5);
};
A

const multiplyByNineFifths = celsius => celsius * (9/5);

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

Review Functions

A

Functions are written to perform a task.
Functions take data, perform a set of tasks on the data, and then return the result.
We can define parameters to be used when calling the function.
When calling a function, we can pass in arguments, which will set the function’s parameters.
We can use return to return the result of a function which allows us to call functions anywhere, even inside other functions.

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

Which of the following demonstrates correct syntax for a function?

Which of the following demonstrates correct syntax for a function?

myFunction = () {

}

const myFunction = () => {

}

const myFunction{ () } (

)

const myFunction = {

}

A

const myFunction = () => {

}

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

What’s the purpose of a parameter?

What’s the purpose of a parameter?

To make the data the function uses visible.

To prevent the function from being called without certain variables defined.

To pass data to a function, which are then used when calling the function.

A

To pass data to a function, which are then used when calling the function.

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

Which of the following is a parameter in the block of code below?

let input = prompt(‘Enter input value’);
const controlVal = input / 2 + 3;
const multiplier = (number, phase) => {
const val = number * controlVal + phase;
console.log(val);
};
Which of the following is a parameter in the block of code below?

input

number

controlVal

val

A

number

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

Which of the following is the correct way to call the function below?

const multiplier = (number) => {
  console.log(3 * number);
};
Which of the following is the correct way to call the function below?

multiplier(5)

multiplier{5}

multiplier[5]

multiplier 5

A

multiplier(5)

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

What will this code print to the console?

const sleepTimer = (alarm) => {
  console.log('My alarm is set for: ' + alarm);
}

sleepTimer(‘8:30AM’);
What will this code print to the console?

My alarm is set for: undefined

My alarm is set for: sleepTimer

My alarm is set for: alarm

My alarm is set for: 8:30AM

A

My alarm is set for: 8:30AM

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

What will this code print to the console?

const workoutJournal = (miles, avgTime) => {
  console.log('I ran ' + miles + ' miles at an average of ' + avgTime + ' per mile.');
}

workoutJournal(‘3’);
What will this code print to the console?

I ran 3 miles at an average of undefined per mile.

Uncaught ReferenceError: avgTime is not defined.

I ran 3 miles at an average of per mile.

I ran 3 miles at an average of 7 minutes per mile.

A

I ran 3 miles at an average of undefined per mile.

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

Which of the following best describes what a function in JavaScript is used for?

Which of the following best describes what a function in JavaScript is used for?

A function is a reusable piece of code that takes an input, operates on it, then returns an output.

A function is used for math formulas.

A function allows for the use of mathematical operators.

A function creates new variables.

A

A function is a reusable piece of code that takes an input, operates on it, then returns an output.

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

How can you call this function?

const getCurrentDate = () => {
  let date = new Date();
  return date;
}
How can you call this function?

getCurrentDate();

const getCurrentDate();

getCurrentDate(){}

getCurrentDate(todaysDate);

A

getCurrentDate();

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

Which of the following most accurately describes the volumeOfCube() function?

let side = 5;

function volumeOfCube () {
  side * side * side;
}
volumeCube();
// Output: 125.
Which of the following most accurately describes the `volumeOfCube()` function?

It is a function declaration.

It is an arrow function declaration.

It is an arrow function.

It is a function expression.

A

It is a function declaration.

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