-
Section 1: Getting Started
-
Section 2: Core Syntax and Types
-
Section 3: Strings and Numbers in Depth
-
Section 4: Control Flow
-
Section 5: Functions
-
Section 6: Objects and Arrays
-
Section 7: Maps, Sets, and Symbols
-
Section 8: Asynchronous JavaScript
-
Section 9: Object-Oriented and Prototypes
-
Section 10: The DOM
-
Section 11: Browser APIs
-
Section 12: Modern JavaScript (ES2015-ES2025)
-
Section 13: Functional Programming Patterns
-
Section 14: Error Handling and Debugging
-
Section 15: Testing
-
Section 16: Accessibility for JavaScript Developers
-
Section 17: Internationalization and Localization
-
Section 18: Performance
-
Section 19: Node.js Fundamentals
-
Section 20: Regular Expressions
-
Section 21: Design Patterns in JavaScript
-
Section 22: Security Basics
-
Section 23: Data Structures and Algorithms in JavaScript
-
Section 24: Practical Projects
-
Section 25: More Advanced Async Patterns
-
Section 26: More Object and Class Practice
-
Section 27: Working with Dates and Internationalization
-
Section 28: Web Components
-
Section 29: More DOM and Browser Practice
-
Section 30: Build Tooling for Vanilla JavaScript
-
Section 31: More Practice Projects
-
Section 32: Interview and Algorithm Practice
-
Section 33: Error Objects (MDN Reference)
-
Section 34: TypedArrays and Binary Data
-
Section 35: Reflection and Metaprogramming (MDN Reference)
-
Section 36: More Global Functions (MDN Reference)
234: Mock Coding Interview Walkthrough in JavaScript
Alright, we've hit the home stretch. You know the syntax, you can handle the asynchronous stuff, and you've built projects. But there is a massive difference between building an app you're passionate about and solving a puzzle on a whiteboard while someone watches you breathe. Interviewing is a specific skill, and it's more about how you think than just getting the code to run.
The Mental Game: Scrambled Tiles and Baskets
Imagine I hand you a giant pile of alphabet tiles. Some are scrambled versions of the same word—like "listen" and "silent." Your job is to group all the words that use the exact same letters into their own separate baskets. If you just looked at every single word and compared it to every other word in the pile, you'd be there all day. That's what we call a "brute force" approach, and it's the first thing an interviewer wants to see you move away from.
Instead, you'd probably do this: take a word, sort the letters alphabetically (so "silent" becomes "eilnst"), and use that sorted version as a label for a basket. Now, every time you pick up a new word, you sort it. If a basket with that label already exists, you toss the word in. If not, you make a new basket with that label. This turns a chaotic search into a streamlined process of "Sort, Label, Store."
Turning the Logic into JavaScript
In a real interview, I want you to talk through that analogy before you touch the keyboard. Once the interviewer nods, you map those "baskets" to a Map and the "labels" to sorted strings. Here is how that looks in actual code.
function groupAnagrams(strs) {
// Our 'baskets' collection
const baskets = new Map();
for (const str of strs) {
// 1. Create the 'label' by sorting the string
// We split into an array, sort it, then join it back to a string
const label = str.split('').sort().join('');
// 2. If the basket doesn't exist yet, initialize it with an empty array
if (!baskets.has(label)) {
baskets.set(label, []);
}
// 3. Toss the original word into its corresponding basket
baskets.get(label).push(str);
}
// The interviewer usually wants an array of arrays, not the Map itself
return Array.from(baskets.values());
}
// Testing it out:
const words = ["eat", "tea", "tan", "ate", "nat", "bat"];
console.log(groupAnagrams(words));
// Output: [ ["eat", "tea", "ate"], ["tan", "nat"], ["bat"] ]
Talking Through the Complexity
Once you finish the code, the interviewer is going to ask you about "Big O." Don't panic. This is where you show you aren't just guessing. I'd explain it like this: "We're iterating through the list of N strings once. Inside that loop, we sort each string. If the average length of a string is K, sorting takes O(K log K). So, the total time complexity is O(N * K log K)."
I'll let you in on a secret: interviewers often care more about you admitting a limitation than pretending the code is perfect. If you can say, "I used a sort here for simplicity, but if the character set was limited (like only lowercase English letters), I could use a frequency counter to get this down to O(N * K)," you've basically won the interview. It shows you know the trade-offs.
📋 Practical Task
The First Unique Character Hunt
It's your turn to apply the "Label and Store" mentality. Write a function called findFirstUniqueChar that takes a string and returns the index of the first character that does not repeat anywhere else in the string. If every character repeats, return -1.
Constraints:
- The input will only contain lowercase English letters.
- Think about how to use a
Mapor a plain JavaScript object to "count" occurrences before deciding which character is the first unique one.
// Expected behavior:
// findFirstUniqueChar("javascript") -> 0 ( 'j' is the first unique)
// findFirstUniqueChar("success") -> 0 ( 's' repeats, 'u' is the first unique at index 1)
// Wait, in "success", 's' is at 0, 5, and 6. 'u' is at index 1 and is unique.
// So findFirstUniqueChar("success") should return 1.
// findFirstUniqueChar("aabb") -> -1
There are no comments for now.