curriculum/challenges/english/blocks/quiz-javascript-functions/66edcc779993c0da6906dbb9.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
Which of the following is the correct way to declare a function in JavaScript?
func greet() {
console.log("Hello there!");
}
defineFunction greet() {
console.log("Hello there!");
}
def greet() {
console.log("Hello there!");
}
function greet() {
console.log("Hello there!");
}
What happens when you call (or execute) a function?
The code inside the function will run and null will always be returned.
Nothing will happen when you call a function.
A TypeError will be thrown and the program will crash.
The code inside the function will run and a value will be returned.
Which of the following is the correct way to call a function?
exampleFunction;
exampleFunction>>;
()exampleFunction();
exampleFunction();
What is the role of the return keyword?
The return keyword will execute the function.
The return keyword will throw a type error.
The return keyword serves no purpose in functions.
The return keyword returns a value from the function.
Which of the following is a valid function expression?
expression function getSum(x, y) {
return x + y;
};
getSum: function(x, y) {
return x + y;
};
function = getSum(x, y) {
return x + y;
};
const getSum = function(x, y) {
return x + y;
};
What are function arguments?
Values that represents the absence of a value.
Special values that act similar to anonymous functions.
Placeholder values used inside of the function.
Real values passed to a function when it is called.
What are function parameters?
Floating point values used inside of the function.
Values passed to a function when it is called.
Values that represent the intentional absence of the value.
Values listed inside the function definition.
What will be logged to the console?
const calculateTotal = (amount, taxRate = 0.05) => {
return amount + (amount * taxRate);
};
console.log(calculateTotal(100));
10
undefined
1
105
Which of the following is the correct syntax for an arrow function?
const sum <<>> (num1, num2) => num1 + num2
const sum === (num1, num2) === num1 + num2
const sum >=> (num1, num2) => num1 + num2
const sum = (num1, num2) => num1 + num2
What will be result for the following code?
function greet() {
const developer = "Jessica";
console.log("Hello there!");
}
console.log(developer);
Nothing will happen and the code will run normally.
The string "Hello there!" will be logged to the console.
The string "Hello!" will be logged to the console.
You will get a reference error because developer is not defined globally.
When can you omit a set of parentheses around a parameter list for an arrow function?
You should always omit the parentheses around a parameter list.
You are never supposed to omit the parentheses for an arrow function.
You should only omit the parentheses when you are working with multiple parameters.
You should only omit the parentheses when you only have one parameter.
When can you omit the curly braces and return keyword for an arrow function?
You should always omit the curly braces and return keyword.
You should never omit the curly braces and return keyword.
When the function body has multiple lines of code.
When the function body consists of a single expression.
What will the following function return?
function exampleFunction() {
return "Hello";
return "World!";
};
"World!"
"Hello World!"
undefined
"Hello"
Which of the following is the correct way to use default parameters?
function sum(num1, num2 <<>> 12) {
return num1 + num2
}
function sum(num1, num2 === 12) {
return num1 + num2
}
function sum(num1, num2 >> 12) {
return num1 + num2
}
function sum(num1, num2 = 12) {
return num1 + num2
}
What will be the result for the following code?
const developer = "Jessica";
function greet() {
console.log("Hello, " + developer)
}
greet();
The string "Hello, developer" will be logged to the console.
An error message will display in the console.
Nothing will display in the console.
The string "Hello, Jessica" will be logged to the console.
What happens if you try to remove the curly braces for a regular function?
An alert box will display on the page with an error.
The program will crash and not start again.
Nothing will happen.
You will get a syntax error.
What will be the result for the following code?
const sum = (num1, num2) => num1 + num2
console.log(sum(0, 0) + 10);
An error message will display in the console.
The number 0 will be logged to the console.
Nothing will be logged to the console.
The number 10 will be logged to the console.
What will be the output for the following code?
const exampleFunction = (param1, param2) => param1 + param2;
console.log(exampleFunction(3, "Something"));
null
undefined
3 + "Something"
"3Something"
What will be the result for the following code?
const sum = (num1, num2) => num1 + num2
console.log(sum(0, 0) + num2);
An error message saying num1 is not defined.
The number 0 will be displayed in the console.
undefined will be displayed in the console.
An error message saying num2 is not defined.
What will be the output for the following code?
const divideTwoNumbers = (num1, num2) => num1 / num2;
console.log(divideTwoNumbers(3, 0));
Error
0
null
Infinity