0
0
Javascriptprogramming~20 mins

Function declaration in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Function Declaration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of a simple function declaration
What is the output of this JavaScript code?
Javascript
function greet(name) {
  return `Hello, ${name}!`;
}

console.log(greet('Alice'));
Agreet Alice
BHello, Alice!
Cundefined
DError: greet is not defined
Attempts:
2 left
πŸ’‘ Hint
Look at how the function returns a string using template literals.
❓ Predict Output
intermediate
2:00remaining
Function hoisting behavior
What will this code output when run?
Javascript
console.log(square(4));

function square(x) {
  return x * x;
}
A16
BReferenceError: square is not defined
CTypeError: square is not a function
Dundefined
Attempts:
2 left
πŸ’‘ Hint
Function declarations are hoisted in JavaScript.
❓ Predict Output
advanced
2:00remaining
Function declaration inside block scope
What is the output of this code?
Javascript
if (true) {
  function sayHi() {
    return 'Hi!';
  }
}

console.log(typeof sayHi);
AReferenceError
B"function"
C"object"
D"undefined"
Attempts:
2 left
πŸ’‘ Hint
Function declarations inside blocks are block-scoped in modern JavaScript.
🧠 Conceptual
advanced
2:00remaining
Difference between function declaration and function expression
Which statement correctly describes a key difference between function declarations and function expressions in JavaScript?
ABoth are hoisted but only function expressions can be called before declaration.
BFunction expressions are hoisted, function declarations are not.
CFunction declarations are hoisted, function expressions are not.
DNeither function declarations nor function expressions are hoisted.
Attempts:
2 left
πŸ’‘ Hint
Think about when you can call the function in the code.
❓ Predict Output
expert
2:00remaining
Output of nested function declarations and variable shadowing
What is the output of this code?
Javascript
function outer() {
  function inner() {
    return 'inner function';
  }
  let inner = 'inner variable';
  return inner;
}

console.log(outer());
Ainner variable
Binner function
CReferenceError
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Variables declared with let shadow function declarations with the same name.