JavaScript Interview Questions for Freshers
12 JavaScript interview questions for freshers and students (0 to 1 year): const and let, types and coercion, equality, scope, arrays and event bubbling. Each answer explains why the other options are wrong.
CoversArraysCoercionCore JavaScriptDOMEqualityEventsObjectsScopeTypesVariables
By Deepak KumarPublished Answers checked by Deepak
Take it as a timed test
- 12 questions
- 15 min
- Pass mark 60%
- Answers shown at the end
No sign-up. Your answers and scores stay in this browser.
This freshers paper has 12 JavaScript questions for freshers and students with roughly 0 to 1 year of experience. It covers const and let, types and coercion, equality, scope, arrays and event bubbling. Ten questions are on this page with full explanations; the timed test also includes two questions that aren't shown here, so practise for understanding rather than memory.
How should you use this paper?
Answer each practice question before opening its explanation, and say your reasoning out loud the way you would in an interview. Then take the timed test: 15 minutes, a pass mark of 60%, with answers shown at the end. Your report breaks your score down by topic and difficulty, and you can retry only the questions you missed.
Practice questions with answers
Try each one before opening the answer. The explanation covers why the other options are wrong. The timed test also uses 2 questions that aren't shown here, so practise for understanding, not memory.
Which statement about const is true?
Show answer and explanation
Answer: A. The variable can't be reassigned, but an object it points to can still be changed
const locks the binding: you can't point the name at a new value. It does not freeze the value itself, so const user = {} still lets you write user.name = 'Ana'. Uppercase names are only a convention for fixed settings, and redeclaring any let or const name in the same scope is a SyntaxError. Use Object.freeze when you need the object itself locked.
What does typeof [] print?
console.log(typeof []);Show answer and explanation
Answer: A. "object"
Arrays are a special kind of object in JavaScript, so typeof reports "object". There is no "array" result. To check for an array, use Array.isArray(value), which returns true only for real arrays, including ones created in another frame or window. This is one of the first type questions in most fresher rounds, often asked together with typeof null.
What do "5" + 3 and "5" - 3 give?
console.log("5" + 3, "5" - 3);Show answer and explanation
Answer: A. 53 2
When either side of + is a string, JavaScript joins them as text, so "5" + 3 is the string "53". The minus operator only works on numbers, so "5" - 3 converts the string to 5 first and gives 2. This difference is a classic source of bugs with form inputs, which are always strings. Convert explicitly with Number(value) before doing arithmetic.
null == undefined is true.
TrueFalse
Show answer and explanation
Answer: True
True. Loose equality treats null and undefined as equal to each other and to nothing else, so null == 0 and undefined == false are both false. That is why value == null is a common, deliberate shortcut for "null or undefined". With strict equality, null === undefined is false because they are different types.
What is the most reliable way to check whether a value is an array?
Show answer and explanation
Answer: A. Array.isArray(value)
Array.isArray is built for exactly this check and works even for arrays from another iframe. typeof never returns "array". Checking length also matches strings and objects that happen to have a length property. instanceof Object is true for almost everything that isn't a primitive, including plain objects, functions and dates, so it can't tell an array apart.
Which of these are primitive types in JavaScript? Select all that apply.
Show answer and explanation
Answer: A. string + B. symbol + D. bigint
JavaScript has seven primitive types: string, number, bigint, boolean, undefined, symbol and null. Primitives are immutable and compared by value. Arrays are not a separate type: they are objects, and objects are compared by reference. Knowing the list matters for questions about copying, equality and typeof, and interviewers often add array as a trap option.
What does this block-scoped let example print?
let x = 1;
{
let x = 2;
}
console.log(x);Show answer and explanation
Answer: A. 1
The inner let x lives only inside the curly braces, so it is a separate variable that shadows the outer one there. After the block ends, the outer x is still 1. Declaring the same name in a nested block is allowed; only redeclaring it in the same scope throws. With var instead of let both lines would share one function-scoped variable and the output would be 2.
What does comparing two identical object literals with === print?
console.log({ a: 1 } === { a: 1 });Show answer and explanation
Answer: A. false
Objects are compared by reference, not by content. Each literal creates a new object in memory, so the two sides are different objects and === returns false, even though they look identical. Two variables are only equal if they point to the same object. To compare contents, compare the fields you care about or use a deep-equality helper.
Match each array method to what it does.
- push
- pop
- shift
- unshift
- Removes the last item
- Adds items to the end
- Removes the first item
- Adds items to the start
Show answer and explanation
Answer: push → Adds items to the endpop → Removes the last itemshift → Removes the first itemunshift → Adds items to the start
push and pop work at the end of the array; unshift and shift work at the start. All four change the original array. push and unshift return the new length, while pop and shift return the removed item. Working at the start is slower on big arrays because every other item has to move one place.
A click happens on a button inside a div, and both have click listeners. What does event bubbling mean here?
Show answer and explanation
Answer: A. The button's listener runs first, then the event travels up and the div's listener runs
By default, events bubble: they fire on the element that was clicked, then on each ancestor up to the document. So the button handler runs before the div handler. Capturing, the opposite direction, only happens if you pass { capture: true }. You can stop the climb with event.stopPropagation(). Bubbling is what makes event delegation possible.
Answered them all? Take the same questions against the clock and get a topic-by-topic report.
Start the timed test