JavaScript Functions & Parameters Quiz

JavaScript
0 Passed
0% acceptance

Explore 50 JavaScript function questions covering declarations, expressions, arrow functions, scopes, parameters, defaults, rest arguments, return values, closures, and execution flow.

50 Questions
~100 minutes
1

Question 1

What does this function log when called?

javascript
function greet() {
  console.log('Hi')
}
greet()
A
Hi
B
undefined
C
Nothing
D
Throws ReferenceError
2

Question 2

What value is logged when the function returns a string?

javascript
function say() {
  return 'hello'
}
console.log(say())
A
hello
B
undefined
C
[Function]
D
null
3

Question 3

What is printed when a function has no return statement?

javascript
function add(a, b) {
  const sum = a + b
}
console.log(add(2, 3))
A
undefined
B
5
C
sum
D
Throws TypeError
4

Question 4

How many times does this function execute console.log?

javascript
function run() {
  console.log('X')
}
run(); run();
A
2
B
1
C
0
D
Depends on engine
5

Question 5

What is logged when passing parameters into a function?

javascript
function print(x) { console.log(x) }
print('A')
A
A
B
undefined
C
x
D
null
6

Question 6

What happens when calling a function expression before it is defined?

javascript
console.log(fn())
const fn = function(){ return 1 }
A
Throws ReferenceError
B
1
C
undefined
D
null
7

Question 7

What is printed when calling a hoisted function declaration?

javascript
console.log(sum(2, 3))
function sum(a, b){ return a + b }
A
5
B
undefined
C
Throws TypeError
D
NaN
8

Question 8

What does this arrow function return?

javascript
const fn = () => 10
console.log(fn())
A
10
B
undefined
C
() => 10
D
Throws ReferenceError
9

Question 9

What value is printed when using an arrow function with block braces but missing return?

javascript
const fn = () => { 3 }
console.log(fn())
A
undefined
B
3
C
{}
D
null
10

Question 10

What is printed here using a function expression?

javascript
const go = function() { return 'ok' }
console.log(go())
A
ok
B
undefined
C
[Function]
D
Throws ReferenceError
11

Question 11

What is logged using a default parameter?

javascript
function speak(msg = 'hi'){ console.log(msg) }
speak()
A
hi
B
undefined
C
msg
D
Throws ReferenceError
12

Question 12

What value prints for this default parameter function?

javascript
function calc(a = 5, b = 3){ return a + b }
console.log(calc(2))
A
5
B
8
C
2
D
undefined
13

Question 13

What is logged when passing undefined to a default parameter?

javascript
function get(x = 'A'){ return x }
console.log(get(undefined))
A
A
B
undefined
C
null
D
Throws TypeError
14

Question 14

What does this return with null and a default param?

javascript
function fn(a = 5){ return a }
console.log(fn(null))
A
null
B
5
C
undefined
D
Throws TypeError
15

Question 15

What is the output when extra arguments are passed?

javascript
function f(a){ return a }
console.log(f(1, 2, 3))
A
1
B
3
C
undefined
D
[1,2,3]
16

Question 16

What does this rest parameter function return?

javascript
function sum(...nums){ return nums.length }
console.log(sum(1,2,3))
A
3
B
undefined
C
6
D
1
17

Question 17

Which value is logged using rest parameters?

javascript
function first(...items){ return items[0] }
console.log(first('A','B'))
A
A
B
B
C
undefined
D
items
18

Question 18

What does this function log with both normal and rest params?

javascript
function wrap(x, ...y){ console.log(y.length) }
wrap(1,2,3,4)
A
3
B
4
C
1
D
undefined
19

Question 19

What happens if rest params are not last?

javascript
function bad(...x, y){}
A
Throws SyntaxError
B
Works normally
C
undefined
D
Throws ReferenceError
20

Question 20

What is printed when calling a function with no arguments but expecting rest params?

javascript
function fn(...a){ console.log(a.length) }
fn()
A
0
B
undefined
C
Throws TypeError
D
null
21

Question 21

What does this function log using the arguments object?

javascript
function f(){ console.log(arguments.length) }
f(1,2,3)
A
3
B
undefined
C
0
D
Throws ReferenceError
22

Question 22

What does accessing arguments[0] return?

javascript
function f(){ return arguments[0] }
console.log(f('A', 'B'))
A
A
B
B
C
undefined
D
Throws TypeError
23

Question 23

What value prints if no arguments are passed?

javascript
function f(){ return arguments[1] }
console.log(f())
A
undefined
B
null
C
Throws TypeError
D
1
24

Question 24

Which keyword cannot be used inside arrow functions?

A
arguments
B
this
C
return
D
const
25

Question 25

What value does this arrow function return?

javascript
const fn = () => arguments
console.log(fn(1,2))
A
Arguments of the outer scope
B
[1,2]
C
undefined
D
Throws TypeError
26

Question 26

What value is returned here?

javascript
function test(){ return }
console.log(test())
A
undefined
B
null
C
test
D
Throws TypeError
27

Question 27

Which value is logged when a return appears before a statement?

javascript
function f(){ return 1; console.log(2) }
console.log(f())
A
1
B
2
C
1 2
D
undefined
28

Question 28

What is returned when a return statement spans lines incorrectly?

javascript
function f(){
  return
  5
}
console.log(f())
A
undefined
B
5
C
null
D
Throws SyntaxError
29

Question 29

What value prints when returning an object literal incorrectly?

javascript
function f(){ return { a: 1 } }
console.log(f().a)
A
1
B
undefined
C
{}
D
null
30

Question 30

What value is returned in this example with parentheses?

javascript
function f(){ return (
    2
  ) }
console.log(f())
A
2
B
undefined
C
Throws TypeError
D
null
31

Question 31

What does this closure return?

javascript
function outer(){
  let x = 1
  return function(){ return x }
}
console.log(outer()())
A
1
B
undefined
C
Throws ReferenceError
D
null
32

Question 32

Which value is logged when reassigning the closed-over variable?

javascript
function make(){
  let n = 5
  return ()=>{ return n }
}
const f = make();
n = 10
console.log(f())
A
5
B
10
C
undefined
D
Throws ReferenceError
33

Question 33

What does this nested function log?

javascript
function a(){
  const x = 'A'
  function b(){ console.log(x) }
  b()
}
a()
A
A
B
undefined
C
x
D
Throws ReferenceError
34

Question 34

What is printed using block scope variables?

javascript
let x = 'global'
function f(){
  let x = 'local'
  return x
}
console.log(f())
A
local
B
global
C
undefined
D
Throws TypeError
35

Question 35

What value prints when accessing a variable before declaration inside a function?

javascript
function f(){ console.log(a); var a = 1 }
f()
A
undefined
B
1
C
Throws ReferenceError
D
null
36

Question 36

Which value is logged inside this arrow function?

javascript
const obj = {
  x: 10,
  f: () => this.x
}
console.log(obj.f())
A
undefined
B
10
C
Throws TypeError
D
null
37

Question 37

What does this regular function return for this.x?

javascript
const obj = {
  x: 10,
  f: function(){ return this.x }
}
console.log(obj.f())
A
10
B
undefined
C
Throws TypeError
D
null
38

Question 38

What does this arrow function return inside setTimeout?

javascript
const obj = {
  x: 7,
  run(){ setTimeout(()=>console.log(this.x), 0) }
}
obj.run()
A
7
B
undefined
C
Throws TypeError
D
null
39

Question 39

What prints when calling a method detached from its object?

javascript
const obj = {
  x: 3,
  f(){ return this.x }
}
const detached = obj.f
console.log(detached())
A
undefined
B
3
C
Throws TypeError
D
null
40

Question 40

Which value is logged when binding this explicitly?

javascript
function show(){ return this.v }
const obj = { v: 20 }
console.log(show.bind(obj)())
A
20
B
undefined
C
Throws TypeError
D
null
41

Question 41

What is logged when a function returns another function?

javascript
function outer(){ return ()=>5 }
console.log(outer()())
A
5
B
undefined
C
[Function]
D
Throws TypeError
42

Question 42

What does this mapping function return?

javascript
const arr = [1,2]
const out = arr.map(x => x * 2)
console.log(out[1])
A
4
B
2
C
undefined
D
Throws TypeError
43

Question 43

Which output is logged when passing a function as a callback?

javascript
function run(cb){ cb() }
run(()=>console.log('X'))
A
X
B
undefined
C
cb
D
Throws TypeError
44

Question 44

What does this reducer function return?

javascript
const nums = [1,2,3]
const total = nums.reduce((a,b)=>a+b,0)
console.log(total)
A
6
B
3
C
undefined
D
Throws TypeError
45

Question 45

What is logged when calling a function that returns a function with arguments?

javascript
function make(x){ return y => x + y }
console.log(make(3)(4))
A
7
B
34
C
undefined
D
Throws TypeError
46

Question 46

Why can functions be passed around as values?

A
Because functions are first-class values in JavaScript.
B
Because functions are stored in a separate memory region.
C
Because functions cannot reference variables.
D
Because only functions run in strict mode.
47

Question 47

Why should deeply nested function chains be avoided?

A
They increase indentation and make the control flow harder to follow.
B
Nested functions are forbidden by ES6.
C
Nested functions cannot access outer scope.
D
They break async operations.
48

Question 48

Why can default parameters improve clarity in APIs?

A
They make the function signature show expected fallbacks directly.
B
They automatically deep clone arguments.
C
They remove the need for return statements.
D
They prevent functions from being called without arguments.
49

Question 49

Why can mutating parameters directly cause confusion?

A
It hides state changes inside the function, making behavior difficult to track.
B
Parameters are always read-only.
C
Mutations disable return values.
D
Mutations prevent closures from forming.
50

Question 50

Why is documenting function behavior important?

A
It clarifies intent behind parameters, return values, and side effects.
B
Functions cannot be understood without comments.
C
Documentation forces engines to optimize the function.
D
Functions stop working if undocumented.

QUIZZES IN JavaScript