learn deep. ship safe.Practice testsFollow ByteMunSubscribe
JavaScript · Fresher

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 Published Answers checked by Deepak

Take it as a timed test

  • 12 questions
  • 15 min
  • Pass mark 60%
  • Answers shown at the end
Start the timed test

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.

Q1Choose one answereasy

Which statement about const is true?

  1. The variable can't be reassigned, but an object it points to can still be changed
  2. The value is deeply immutable, including nested objects
  3. A const name must be written in uppercase
  4. It can be declared again later in the same scope
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.

Q2What does this code output?easy

What does typeof [] print?

javascript
console.log(typeof []);
  1. "object"
  2. "array"
  3. "list"
  4. "undefined"
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.

Q3What does this code output?medium

What do "5" + 3 and "5" - 3 give?

javascript
console.log("5" + 3, "5" - 3);
  1. 53 2
  2. 8 2
  3. 53 NaN
  4. 8 8
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.

Q4True or falseeasy

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.

Q5Choose one answereasy

What is the most reliable way to check whether a value is an array?

  1. Array.isArray(value)
  2. typeof value === "array"
  3. value.length !== undefined
  4. value instanceof Object
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.

Q6Select all that applyeasy

Which of these are primitive types in JavaScript? Select all that apply.

  1. string
  2. symbol
  3. array
  4. bigint
  5. object
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.

Q7What does this code output?easy

What does this block-scoped let example print?

javascript
let x = 1;
{
  let x = 2;
}
console.log(x);
  1. 1
  2. 2
  3. It throws because x is declared twice
  4. undefined
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.

Q8What does this code output?easy

What does comparing two identical object literals with === print?

javascript
console.log({ a: 1 } === { a: 1 });
  1. false
  2. true
  3. It throws a SyntaxError
  4. undefined
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.

Q9Match each item on the lefteasy

Match each array method to what it does.

  1. push
  2. pop
  3. shift
  4. 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.

Q10Choose one answermedium

A click happens on a button inside a div, and both have click listeners. What does event bubbling mean here?

  1. The button's listener runs first, then the event travels up and the div's listener runs
  2. Only the div's listener runs
  3. The div's listener runs first, then the button's
  4. Both listeners run at exactly the same time
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

More JavaScript quizzes

All JavaScript quizzes →