The basics every interviewer assumes you know: types, conversions, loops, arrays, strings, reading errors and fixing syntax, shown in JavaScript, PHP and Python side by side.
Readiness: 0 of 30 nailed
How to use this page:1. Read a question2. Type your answer3. Check with AI4. Open the model answer5. Timed drill when you’re 70% ready
Data from forms, URLs and APIs usually arrives as text (strings). '4' is the character four, not the number four. '4' + '2' glues text into '42', while 4 + 2 adds to 6. You convert each item with the language’s number function, and to build 427 you join the strings first, then convert once.
“The values are strings, so I map each one through a number conversion: map(Number) in JS, array_map('intval', …) in PHP, int() in Python. To get 427 I join them into one string first and convert once.”
+ means two things in JS: add numbers or join strings. If either side is a string, it joins: '5' + 3 = '53'. - only means subtract, so JS converts '5' to a number: 5 - 3 = 2. PHP avoids this confusion by using . for joining strings.
Say it like this in the interview
“'53' and 2. With +, if one side is a string JavaScript concatenates. Minus has no string meaning, so it coerces both sides to numbers.”
Traps that make people fail
Forgetting to convert form values before adding them.
== is “roughly equal”: it converts types before comparing, so '5' == 5 is true. === is “exactly equal”: same value and same type. JavaScript and PHP both have this. Use === by default to avoid surprises.
“Double equals does type coercion before comparing; triple equals checks value and type with no conversion. I always use strict equality unless I deliberately want coercion, because loose comparison causes bugs like 0 == '' being true.”
Traps that make people fail
Not knowing that PHP 8 changed string-to-number comparison.
Each language has number and string conversion functions. They differ on messy input: some stop at the first bad character, some fail, some give 0.
Say it like this in the interview
“JS: Number('42'), parseInt('42', 10), String(42). PHP: (int) '42', intval, (string) 42. Python: int('42'), str(42). For '42abc': Number gives NaN, parseInt gives 42, PHP (int) gives 42 (with a warning in PHP 8 for non-numeric strings in arithmetic), Python raises ValueError. I validate input rather than relying on lenient parsing.”
undefined means “never given a value”. null means “deliberately empty”. PHP has null, Python has None, both meaning “no value”.
Say it like this in the interview
“undefined is the default for missing variables, properties and return values; null is an intentional absence. null == undefined is true but === is false. In APIs I use null for ‘no value’ explicitly.”
JSON is a text format for sending data between programs: objects in {}, lists in [], strings in double quotes. You turn your data into JSON text to send it, and parse JSON text back into data when you receive it.
Say it like this in the interview
“JSON is a language-independent text format. JS: JSON.stringify and JSON.parse; PHP: json_encode and json_decode($s, true) for arrays; Python: json.dumps and json.loads. Parsing untrusted JSON needs error handling.”
Walk from the last character to the first and build a new string. A palindrome reads the same both ways (racecar), so compare the word with its reverse, after lowercasing and removing spaces.
// JavaScript
function reverse(text) {
let result = '';
for (let i = text.length - 1; i >= 0; i--) {
result += text[i];
}
return result;
}
function isPalindrome(text) {
const clean = text.toLowerCase().replace(/[^a-z0-9]/g, '');
return clean === reverse(clean);
}
// PHP
function reverseText(string $text): string {
$result = '';
for ($i = strlen($text) - 1; $i >= 0; $i--) {
$result .= $text[$i];
}
return $result;
}
Say it like this in the interview
“I loop from the last index down to zero, appending each character. That’s O(n) time. For a palindrome I normalise case and strip non-letters, then compare with the reverse. A faster version uses two pointers from both ends and stops at the first mismatch, with O(1) extra space.”
They will probably ask next
“Do it with two pointers.”
“What about emoji or accented characters?” In JS use [...text] to split by characters, not code units.
Traps that make people fail
Starting the loop at text.length instead of text.length - 1 (off-by-one).
Using <= vs < wrong and missing the first character.
Go through each character; if it’s one of a e i o u (any case), add one.
// JavaScript
const countVowels = (s) => [...s.toLowerCase()].filter((c) => 'aeiou'.includes(c)).length;
// PHP
// preg_match_all('/[aeiou]/i', $s);
# Python
# sum(c in 'aeiou' for c in s.lower())
Say it like this in the interview
“Loop with a set of vowels, lowercase each character, count matches. O(n).”
Use a map / dictionary / associative array: a box of labelled drawers. For each word, open the drawer with that label and add 1. If the drawer doesn’t exist yet, start it at 0.
// JavaScript
const counts = {};
for (const word of 'the cat and the hat'.split(' ')) {
counts[word] = (counts[word] || 0) + 1;
}
// { the: 2, cat: 1, and: 1, hat: 1 }
// PHP
$counts = [];
foreach (explode(' ', 'the cat and the hat') as $word) {
$counts[$word] = ($counts[$word] ?? 0) + 1;
}
// or simply: array_count_values(explode(' ', $text))
# Python
from collections import Counter
counts = Counter('the cat and the hat'.split())
Say it like this in the interview
“I split the sentence into words and use a hash map keyed by word, incrementing the count each time. One pass, O(n) time.”
They will probably ask next
“Now return the most frequent word.”
“Ignore case and punctuation.”
Traps that make people fail
Using nested loops (O(n²)) to count: works, but interviewers expect the map approach.
JavaScript’s default sort() compares items as strings, like a dictionary: '1', '10', '100', '9'. To sort numbers you must pass a compare function.
Say it like this in the interview
“[1, 10, 100, 9], because default sort converts to strings. For numbers I write arr.sort((a, b) => a - b). Also note sort mutates the original array; toSorted() returns a copy.”
Some methods change the array in place (dangerous when it’s shared, e.g. React state). Others return a new array and leave the original alone.
Say it like this in the interview
“In JS, push, pop, shift, unshift, splice, sort, reverse and fill mutate; map, filter, slice, concat, toSorted, toReversed, toSpliced and with return new arrays. In PHP, sort and its relatives mutate by reference; array_map and array_filter return new arrays.”
This tests whether you can write a loop and an if/else in the right order. Check the “both” case first, otherwise 15 stops at “Fizz”. % (modulo) gives the remainder: 15 % 3 === 0 means divisible.
for (let i = 1; i <= 15; i++) {
if (i % 15 === 0) console.log('FizzBuzz');
else if (i % 3 === 0) console.log('Fizz');
else if (i % 5 === 0) console.log('Buzz');
else console.log(i);
}
Say it like this in the interview
“Loop from 1 to n; check divisible-by-15 first because it satisfies both other conditions; then 3, then 5, else print the number.”
Traps that make people fail
Checking % 3 before % 15.
Loop from 0 or to < 15, which prints the wrong range.
Walk through once, carrying two “best so far” values. When you find something bigger than the best, the old best becomes second.
function topTwo(nums) {
let first = -Infinity, second = -Infinity;
for (const n of nums) {
if (n > first) { second = first; first = n; }
else if (n > second && n !== first) { second = n; }
}
return [first, second];
}
Say it like this in the interview
“One pass, two variables. If a number beats the max, the max moves down to second place. O(n), better than sorting which is O(n log n).”
They will probably ask next
“What if the array has fewer than two distinct numbers?”
Traps that make people fail
Initialising with 0, which fails when all numbers are negative.
Recursion is a function that calls itself on a smaller version of the problem, like Russian dolls. Every recursive function needs a base case (the smallest doll) or it runs forever and crashes with a stack overflow.
function factorial(n) {
if (n <= 1) return 1; // base case
return n * factorial(n - 1); // smaller problem
}
// factorial(4) = 4 * 3 * 2 * 1 = 24
Say it like this in the interview
“A function that solves a problem by calling itself on a smaller input, with a base case that stops it. Each call uses stack memory, so very deep recursion can overflow. For factorial an iterative loop works just as well.”
for when you need the index or a counter; while when you don’t know how many times (keep going until something happens); for...of/foreach to simply visit every item; map/filter to build a new array.
Say it like this in the interview
“Classic for for index control, while for condition-driven loops like reading until EOF, for...of in JS or foreach in PHP for iteration, and map/filter/reduce when transforming data without mutation. I choose for readability first.”
% 10 gives the last digit; dividing by 10 and dropping the decimal removes it. Repeat until nothing is left.
function sumDigits(n) {
n = Math.abs(n);
let sum = 0;
while (n > 0) {
sum += n % 10;
n = Math.floor(n / 10);
}
return sum;
}
Say it like this in the interview
“Loop: add n % 10, then n = Math.floor(n / 10), until n is 0. The string version String(n).split('').reduce(...) also works, but the math version shows understanding.”
Recursion fits naturally when the data is nested (trees, folders, comments with replies). Loops are simpler and safer for flat lists.
Say it like this in the interview
“Recursion for naturally recursive structures: trees, nested JSON, divide and conquer. Loops for linear iteration. Deep recursion risks stack overflow, so for very deep data I use an explicit stack.”
const user = users.find(u => u.id === id);
console.log(user.name);
In simple words
Read errors literally. “Cannot read name of undefined” means: the thing before.name is undefined. Here user is undefined because find didn’t match anything. The bug is not on this line; it’s that the data you expected doesn’t exist.
Say it like this in the interview
“The object before .name is undefined. I check the line number in the stack trace, log the variable just before it, and find out why it’s empty: maybe id is a string '5' while u.id is the number 5, so the strict comparison never matches. Then I fix the cause and add a guard like user?.name or an explicit not-found branch.”
They will probably ask next
“What is optional chaining?” user?.name returns undefined instead of throwing.
Traps that make people fail
Wrapping everything in try/catch to hide the error instead of finding the cause.
Only reading the last line of the stack trace. Your own file is usually lower down.
<?php
function greet($name) {
$message = "Hello " + $name
if ($name == "admin") {
echo $message
}
In simple words
Syntax errors are grammar mistakes: the code can’t even start. The common ones: missing ;, missing closing } or ), wrong concatenation operator, and unclosed quotes. The error line number is often the line after the real mistake.
Say it like this in the interview
“Three problems: PHP concatenates with . not +; both statements are missing semicolons; and the function’s closing brace is missing. PHP would report ‘unexpected token if’ on line 4 because line 3 never ended.”
They will probably ask next
“Why does the error point to the next line?” Because the parser only realises the statement didn’t end when it hits the next token.
Traps that make people fail
Looking only at the exact line number in the error.
A stack trace is the breadcrumb trail of function calls that led to the error. The top shows where it broke; lower lines show who called it. Look for the first line that’s your code.
Say it like this in the interview
“The first line is the error type and message; then frames from the innermost call outward. I skip library frames and find the first frame in my own files, which tells me the file and line to inspect, and the frames below show how execution got there.”
console.log prints what you guessed might be useful. A debugger pauses the program so you can inspect everything and step line by line.
Say it like this in the interview
“Logs are quick and work everywhere, including production. A debugger with breakpoints lets me inspect all variables and step through execution, faster for complex bugs. I use both: breakpoints locally, structured logging in production.”
Big-O describes how work grows as input grows. If you check every item once, doubling the input doubles the work: O(n). A loop inside a loop compares every item with every other: 1,000 items means 1,000,000 steps: O(n²). Looking up a key in a hash map is O(1): instant no matter the size.
O(1) array[5], map lookup instant
O(log n) binary search halves each step
O(n) one loop grows with input
O(n log n) good sorting sort()
O(n²) nested loops slow at 10,000+ items
Say it like this in the interview
“Big-O is the growth rate of time or memory relative to input size, ignoring constants. A nested loop over the same array is O(n²). I usually fix that with a hash map, trading O(n) memory for O(n) time.”
They will probably ask next
“What’s the complexity of array.includes inside a loop?” O(n²): includes is itself a loop.
Traps that make people fail
Not noticing hidden loops: indexOf, in_array, includes are all O(n).
const a = { score: 1 };
const b = a;
b.score = 99;
console.log(a.score);
In simple words
Objects and arrays are stored by reference. b = a doesn’t copy the object; it copies the address. Both variables point to the same house, so painting it through b changes what a sees. const only stops you reassigning a, not changing what’s inside.
Say it like this in the interview
“99. Objects are reference types, so b and a point to the same object. To copy it I’d use { ...a } for a shallow copy or structuredClone(a) for a deep copy.”
Traps that make people fail
Thinking const makes objects immutable.
In PHP, arrays are copied on assignment but objects are not, which confuses people switching languages.
add puts changes in the box, commit seals the box with a label (saved locally), push sends your boxes to the shared server, pull brings everyone else’s boxes to you.
Say it like this in the interview
“add stages changes, commit records a snapshot locally with a message, push uploads commits to the remote, pull fetches and merges remote changes. I commit small, focused changes with clear messages.”
Because your job is to know if the code AI writes is correct, safe and fast, and to fix it when it isn’t. You can’t judge what you don’t understand.
Say it like this in the interview
“AI makes writing code faster, but someone has to review it, debug it in production, and make design decisions. Fundamentals are what let me catch an AI suggestion that’s O(n²), insecure or subtly wrong.”
Solve it by hand on a tiny example first, write the steps in plain words (pseudocode), then turn each step into code.
Say it like this in the interview
“I write a small example and solve it manually, note each step I took, turn those steps into pseudocode, check edge cases, then translate to code. It turns a vague problem into a list of small, solvable steps.”