5 JavaScript Interview Questions That Actually Matter

K ManojK Manoj
2 min read

🔸Introduction

Remember those JavaScript concepts we explored together? The three musketeers (var, let, const), execution context mysteries, hoisting magic, scope chains, and closures Well, it's time to put that knowledge to the test!

Here are 5 interview questions that directly stem from our previous deep dives. Think of this as your knowledge checkpoint.

Question 1: What happens in this block scope scenario?

let x = 1;
{
  console.log(x); 
  let x = 2;
}

Answer: Throws ReferenceError due to temporal dead zone - inner let x shadows outer x but isn't initialized yet.


Question 2: Explain what happens to the call stack in this recursive function.

function factorial(n) {
  if (n <= 1) return 1;
  return n * factorial(n - 1);
}
factorial(3);

Answer: Call stack grows: factorial(3)factorial(2)factorial(1), then unwinds as each returns: 12*13*2.


Question 3: What will this code output and why?

console.log(fn1); 
console.log(fn2()); 

var fn1 = 'hello';
function fn2() {
  return 'world';
}

Answer: First prints "undefined" (var declaration hoisted), second prints "world" (function declaration fully hoisted).


Question 4: Trace the scope chain in this nested function.

var global = 'global';

function outer() {
  var outerVar = 'outer';

  function inner() {
    var innerVar = 'inner';
    console.log(innerVar);  
    console.log(outerVar);  
    console.log(global);    
  }

  inner();
}
outer();

Answer: Prints "inner", "outer", "global". Scope chain: inner → outer → global environments.


Question 5: How do closures affect memory management?

function largeDataFunction() {
  var largeData = new Array(1000000).fill('data');

  return function() {
    return largeData.length;
  };
}

var result = largeDataFunction();
// What happens to largeData?

Answer: largeData remains in memory because returned function closes over it. Memory won't be freed until result is dereferenced.

🎯 Conclusion

If you aced these questions, congratulations! You've truly grasped the core JavaScript concepts we explored. If you stumbled on any, no worries—go back to the specific blog posts and reinforce those concepts.

✍️ Missed My Last Blog?

https://kmanoj.hashnode.dev/closures-in-javascript

🔍 Dive deep into JavaScript closures—what they are, how they retain access to outer scope, and why they’re essential for writing modular, reusable, and private code. Learn through practical examples like counters, once-functions, and preserving state across executions.

🤝 Connect with Me

If you enjoyed this blog and want to stay updated with more JavaScript insights, developer tips, and tech deep-dives — feel free to connect with me across platforms:

🔗 LinkedIn: Connect with me on LinkedIn

📝 Medium: Follow me on Medium

🌐 Hashnode: Check out my Hashnode blog

I appreciate your support and look forward to connecting with fellow devs, learners, and curious minds like you! 🚀

0
Subscribe to my newsletter

Read articles from K Manoj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

K Manoj
K Manoj

Backend Web Developer | Security Enthusiast |