Quiz: JavaScript Functions

Research based quiz that cover function declarations, expressions, arrow functions, self-invoking functions, parameters, rest syntax, and more.

1.

What is the correct syntax for a function declaration in JavaScript?

2.

What will this code output?

javascript
1
2
3
4
console.log(square(3));
function square(x) {
  return x * x;
}
3.

What is the output of the following code?

javascript
1
2
3
4
5
const add = function(a, b) {
  return a + b;
};

console.log(add(2, 3));
4.

What is the output of this arrow function?

javascript
1
2
const multiply = (a, b) => a * b;
console.log(multiply(3, 4));
5.

What will this code output?

javascript
1
2
3
4
5
function greet(name = "Guest") {
  return "Hello, " + name + "!";
}

console.log(greet());