💼 JavaScript Coding Interview Questions for Freshers 🚀
Crack your next tech interview with these essential JS problems—logic + code explained clearly!
Whether you're preparing for your first role or a coding bootcamp interview, these questions are frequently asked and test your core logic-building skills.
---
🔹 1️⃣ Reverse a String (Without Built-in Methods)
👨💻 Use a loop to reverse manually:
function reverseString(str) {
let reversed = '';
for (let i = str.length - 1; i >= 0; i--) {
reversed += str[i];
}
return reversed;
}
---
🔹 2️⃣ Find the Missing Number (1 to N Sequence)
👨💻 Use the sum formula and subtract array values:
function findMissing(arr, n) {
let sum = (n * (n + 1)) / 2;
for (let num of arr) {
sum -= num;
}
return sum;
}
---
🔹 3️⃣ Check if a Number is Prime
👨💻 Efficient method with loop till √n:
function isPrime(num) {
if (num <= 1) return false;
for (let i = 2; i * i <= num; i++) {
if (num % i === 0) return false;
}
return true;
}
---
🔹 4️⃣ First Non-Repeating Character in a String
👨💻 Use an object to count character frequencies:
function firstUniqueChar(str) {
const count = {};
for (let char of str) {
count[char] = (count[char] || 0) + 1;
}
for (let char of str) {
if (count[char] === 1) return char;
}
return null;
}
---
🔹 5️⃣ Implement a Basic LRU Cache
👨💻 Using Map() to manage key order and size:
class LRUCache {
constructor(capacity) {
this.capacity = capacity;
this.cache = new Map();
}
get(key) {
if (!this.cache.has(key)) return -1;
const value = this.cache.get(key);
this.cache.delete(key);
this.cache.set(key, value); // Move to end (recently used)
return value;
}
put(key, value) {
if (this.cache.has(key)) this.cache.delete(key);
if (this.cache.size >= this.capacity) {
const firstKey = this.cache.keys().next().value;
this.cache.delete(firstKey);
}
this.cache.set(key, value);
}
}
---
💡 Pro Tip:
📌 Practice each question with variations
📌 Focus on clean logic and explaining your approach out loud
📌 Use platforms like LeetCode, CodeWars, and JSFiddle for hands-on practice
---
💬 Preparing for your first JavaScript interview? Let me know which one you'd like explained step-by-step!
❤️ Double Tap or Save this post for revision!