0
0
Javascriptprogramming~20 mins

Return values in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Return Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this function call?
Consider the following JavaScript function. What will be logged to the console when foo() is called?
Javascript
function foo() {
  return 5 + 3;
}
console.log(foo());
Aundefined
B8
CNaN
DError
Attempts:
2 left
πŸ’‘ Hint
Remember that the return statement sends a value back to where the function was called.
❓ Predict Output
intermediate
2:00remaining
What does this function return?
What is the value of result after calling bar()?
Javascript
function bar() {
  let x = 10;
  if (x > 5) {
    return x * 2;
  }
  return x / 2;
}
const result = bar();
A10
B5
Cundefined
D20
Attempts:
2 left
πŸ’‘ Hint
Check the condition inside the function and which return statement runs first.
❓ Predict Output
advanced
2:00remaining
What is the output of this nested function call?
What will be printed when this code runs?
Javascript
function outer() {
  function inner() {
    return 'Hello';
  }
  return inner();
}
console.log(outer());
AError
Bundefined
CHello
Douter
Attempts:
2 left
πŸ’‘ Hint
The outer function calls the inner function and returns its result.
❓ Predict Output
advanced
2:00remaining
What does this function return when no explicit return is given?
What is the output of this code?
Javascript
function noReturn() {
  let a = 5;
  let b = 10;
  let c = a + b;
}
console.log(noReturn());
Aundefined
BError
CNaN
D15
Attempts:
2 left
πŸ’‘ Hint
If a function does not return a value explicitly, what does it return by default?
❓ Predict Output
expert
2:00remaining
What is the output of this asynchronous function?
What will be logged to the console when this code runs?
Javascript
async function asyncFunc() {
  return 'Done';
}
asyncFunc().then(console.log);
ADone
BPromise { 'Done' }
Cundefined
DError
Attempts:
2 left
πŸ’‘ Hint
Remember that async functions return a Promise, but using .then() logs the resolved value.