JavaScript interview questions for junior developers, answered
Ten JavaScript interview questions junior developers get asked, with short answers, runnable examples, and the follow-ups interviewers like to ask next.

Junior JavaScript interviews rarely try to trip you up with obscure trivia. They check whether you understand the handful of ideas that cause most real bugs: how variables are scoped, how values are compared and copied, and how code that waits for something runs. If you can explain those clearly, with a small example, you are ahead of most candidates.
Below are ten questions that come up again and again, each with a short answer you could say out loud, a runnable example, and the follow-up an interviewer is likely to ask next. Where it helps, we point you to matching start.dev Challenges so you can practise writing the code, not just reading about it.
1. What is the difference between var, let, and const?
var is function-scoped, while let and const are block-scoped, meaning they only exist inside the nearest pair of curly braces. const stops you from reassigning the variable, but it does not make the value immutable.
const items = ['a', 'b']
items.push('c') // allowed: the array is changed, not reassigned
// items = [] // TypeError: Assignment to constant variable
if (true) {
let inside = 1
var leaky = 2
}
console.log(typeof inside) // 'undefined' (not accessible outside the block)
console.log(leaky) // 2Likely follow-up: which one should you use by default? Use const, switch to let only when you need to reassign, and avoid var. The Let And Const (opens in a new tab) lesson covers this.
2. What is scope?
Scope decides where a variable can be read. A variable declared inside a function or block is not visible outside it, while code inside can see variables from the scopes around it.
const greeting = 'Hello'
function welcome(name) {
const message = greeting + ', ' + name
return message
}
console.log(welcome('Ada')) // 'Hello, Ada'
console.log(typeof message) // 'undefined'Likely follow-up: what happens if two variables share a name in different scopes? The inner one shadows the outer one inside its own scope. See the Scope (opens in a new tab) lesson.
3. What is hoisting?
Before running your code, JavaScript sets up declarations for the scope. Function declarations are available from the top of their scope. A var exists from the top too, but its value is undefined until the assignment runs. A let or const is also hoisted, but reading it before its declaration throws a ReferenceError.
console.log(a) // undefined
var a = 1
console.log(sayHi()) // 'hi' (function declarations work early)
function sayHi() { return 'hi' }
// console.log(b) // ReferenceError
let b = 2Likely follow-up: why is the let error considered helpful? It catches a use-before-define mistake instead of quietly giving you undefined.
4. What is the difference between == and ===?
=== compares value and type with no conversion. == converts the values to a common type first, which produces surprises. Default to ===.
console.log(5 === '5') // false
console.log(5 == '5') // true
console.log(0 == '') // true
console.log(null == undefined) // true
console.log(null === undefined) // falseLikely follow-up: is there ever a reason to use ==? Some teams allow value == null as shorthand for "null or undefined," but it is fine to say you use === everywhere. The Comparison And Equality (opens in a new tab) lesson goes through the rules.
Practise it: the Conditionals in JavaScript challenges.
5. What is the difference between null and undefined?
undefined means a value was never assigned, such as a missing property or a function with no return. null is a value you assign on purpose to mean "nothing here." One quirk worth knowing: typeof null is 'object', a long-standing mistake in the language.
let notSet
const empty = null
console.log(notSet) // undefined
console.log(empty) // null
console.log(typeof notSet) // 'undefined'
console.log(typeof empty) // 'object'The More Types (opens in a new tab) lesson covers null, undefined, and typeof.
6. What is a closure?
A closure is a function that remembers the variables from the place where it was created, even after that outer function has finished running.
function makeCounter() {
let count = 0
return function () {
count += 1
return count
}
}
const counter = makeCounter()
console.log(counter()) // 1
console.log(counter()) // 2Each call to makeCounter creates its own private count, which nothing else can touch. Likely follow-up: where would you use one? Private state, callbacks, and functions like debounce. Our guide to JavaScript closures walks through more examples.
Practise it: the JavaScript Functions challenges.
7. Are values copied or shared?
Primitives such as numbers, strings, and booleans are copied when you assign them. Objects and arrays are shared: two variables can point at the same object, so a change through one shows up in the other.
const a = { score: 1 }
const b = a
b.score = 99
console.log(a.score) // 99
const copy = { ...a }
copy.score = 5
console.log(a.score) // 99 (unchanged)Likely follow-up: how do you copy an object? The spread syntax makes a shallow copy, which only copies the top level. See value vs reference in JavaScript for the details.
Practise it: the JavaScript Objects and JavaScript Arrays challenges.
8. What is the difference between map and forEach?
map returns a new array with one result per item. forEach returns nothing and is used for side effects such as logging. If you are not using the array that map returns, you wanted forEach.
const nums = [1, 2, 3]
const doubled = nums.map((n) => n * 2)
console.log(doubled) // [2, 4, 6]
nums.forEach((n) => console.log(n)) // logs 1, 2, 3 and returns undefinedLikely follow-up: how would you add up the values? Use reduce, as in our guide to JavaScript array methods. The ideas build on Callbacks (opens in a new tab), which is worth reviewing if callbacks still feel fuzzy.
Practise it: the JavaScript Array Methods challenges.
9. What is a promise, and what does async/await do?
A promise is an object that stands for a value that is not ready yet. It is pending, then either fulfilled with a value or rejected with an error. async and await let you write code that waits for a promise in a normal top-to-bottom style. An async function always returns a promise, and you handle failures with try and catch.
async function loadUser(id) {
try {
const response = await fetch('/api/users/' + id)
if (!response.ok) throw new Error('Request failed')
return await response.json()
} catch (error) {
console.log('Could not load user:', error.message)
return null
}
}Likely follow-up: how do you run several requests at once? Start them together and wait with Promise.all. The lessons on Promises (opens in a new tab), Async Await (opens in a new tab), and Promise All (opens in a new tab) cover this, and so does async/await explained.
Practise it: the Async JavaScript challenges.
10. In what order does this code run?
This is the event loop question in disguise. JavaScript runs your synchronous code first. Promise callbacks run next, and timer callbacks such as setTimeout run after that, even with a delay of zero.
console.log('1')
setTimeout(() => console.log('2'), 0)
Promise.resolve().then(() => console.log('3'))
console.log('4')
// Output: 1, 4, 3, 2You do not need to recite the internals. Saying "synchronous code first, then promises, then timers" and tracing an example is a strong answer for a junior role.
Practise with Challenges
Knowing an answer and writing the code under pressure are different skills, and junior interviews test both. start.dev Challenges are short, hands-on tasks you solve in the browser: tens of them, on every JavaScript topic above, from beginner to advanced. Start with the topic you answered worst, move up a level once it feels easy, and browse all the sets on the Challenges page.
How to answer well in the interview
A few habits matter more than memorising definitions:
- Answer in two parts. Give the one-sentence definition first, then a tiny example.
- Think out loud. If you are unsure, say what you do know and reason from there. Interviewers want to see how you think.
- Admit gaps calmly. "I have not used that, but I would expect it to work like this" is better than guessing confidently.
- Run the code in your head. For output questions, go line by line and say what each one does.
Fill in the gaps
If any answer felt shaky, work through the matching lessons in JavaScript Basics (opens in a new tab) for the fundamentals, then Intermediate JavaScript (opens in a new tab) for promises, callbacks, and working with arrays.








