Back to templates
consulting assessment

JavaScript Mastery — 155 Interview Questions

Test your JavaScript knowledge with 155 curated interview questions covering closures, prototypes, async, ES6+, and more.

Request customization
🌐
Bilingual / Bilingüe

This template includes both English and Spanish versions. Scroll down to find "Versión Española".

JavaScript Mastery: 155 Interview Questions

Test your JavaScript knowledge from basic to advanced. Each question includes multiple choice options, the correct answer, and a detailed explanation. Based on lydiahallie/javascript-questions.

This is Part 1 (Questions 1-30). The full course contains 155 questions organized by difficulty.


Question 1: Variable Hoisting

What’s the output?

function sayHi() {
  console.log(name);
  console.log(age);
  var name = 'Lydia';
  let age = 21;
}

sayHi();
  • A: Lydia and undefined
  • B: Lydia and ReferenceError
  • C: ReferenceError and 21
  • D: undefined and ReferenceError

Correct Answer: D

Explanation: Within the function, the name variable declared with var gets hoisted with a default value of undefined. Variables declared with let are hoisted but not initialized — they exist in the “temporal dead zone” until the declaration line. Accessing age before its declaration throws a ReferenceError.


Question 2: var vs let in Loops

What’s the output?

for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 1);
}

for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 1);
}
  • A: 0 1 2 and 0 1 2
  • B: 0 1 2 and 3 3 3
  • C: 3 3 3 and 0 1 2

Correct Answer: C

Explanation: The setTimeout callback runs after the loop finishes. With var, i is global-scoped so all callbacks see i = 3. With let, i is block-scoped — each iteration creates a new binding, so callbacks see 0, 1, 2 respectively.


Question 3: Arrow Functions and this

What’s the output?

const shape = {
  radius: 10,
  diameter() {
    return this.radius * 2;
  },
  perimeter: () => 2 * Math.PI * this.radius,
};

console.log(shape.diameter());
console.log(shape.perimeter());
  • A: 20 and 62.83185307179586
  • B: 20 and NaN
  • C: 20 and 63
  • D: NaN and 63

Correct Answer: B

Explanation: Arrow functions don’t have their own this — they inherit it from the surrounding scope (not the object). So this.radius in the arrow function is undefined, and 2 * Math.PI * undefined is NaN. The regular function diameter() correctly uses the object as this.


Question 4: Unary Operators and Type Coercion

What’s the output?

+true;
!'Lydia';
  • A: 1 and false
  • B: false and NaN
  • C: false and false

Correct Answer: A

Explanation: The unary + converts its operand to a number. true becomes 1, false becomes 0. The ! operator checks if the value is falsy. 'Lydia' is a truthy string, so !'Lydia' returns false.


Question 5: Bracket vs Dot Notation

Which one is true?

const bird = {
  size: 'small',
};

const mouse = {
  name: 'Mickey',
  small: true,
};
  • A: mouse.bird.size is not valid
  • B: mouse[bird.size] is not valid
  • C: mouse[bird["size"]] is not valid
  • D: All of them are valid

Correct Answer: A

Explanation: With bracket notation, JavaScript evaluates the expression inside the brackets first. bird.size is "small", so mouse["small"] returns true. But with dot notation, mouse.bird is undefined (no bird key), and accessing .size on undefined throws an error.


Question 6: Object References

What’s the output?

let c = { greeting: 'Hey!' };
let d;

d = c;
c.greeting = 'Hello';
console.log(d.greeting);
  • A: Hello
  • B: Hey!
  • C: undefined
  • D: ReferenceError
  • E: TypeError

Correct Answer: A

Explanation: Objects are assigned by reference. When d = c, both variables point to the same object in memory. Changing c.greeting also changes what d sees, since they reference the same object.


Question 7: Equality Operators with Wrapper Objects

What’s the output?

let a = 3;
let b = new Number(3);
let c = 3;

console.log(a == b);
console.log(a === b);
console.log(b === c);
  • A: true false true
  • B: false false true
  • C: true false false
  • D: false true true

Correct Answer: C

Explanation: new Number(3) creates an object, not a primitive. == checks value only (coercion), so 3 == Number{3} is true. === checks both value and type — since Number{3} is an object and 3 is a number, both strict comparisons return false.


Question 8: Static Methods

What’s the output?

class Chameleon {
  static colorChange(newColor) {
    this.newColor = newColor;
    return this.newColor;
  }

  constructor({ newColor = 'green' } = {}) {
    this.newColor = newColor;
  }
}

const freddie = new Chameleon({ newColor: 'purple' });
console.log(freddie.colorChange('orange'));
  • A: orange
  • B: purple
  • C: green
  • D: TypeError

Correct Answer: D

Explanation: colorChange is a static method — it exists only on the class constructor, not on instances. Calling freddie.colorChange() throws a TypeError because the method is not available on the instance.


Question 9: Global Object Quirks

What’s the output?

let greeting;
greetign = {}; // Typo!
console.log(greetign);
  • A: {}
  • B: ReferenceError: greetign is not defined
  • C: undefined

Correct Answer: A

Explanation: The typo greetign (without let/const/var) creates a property on the global object. It logs {} successfully. Using "use strict" would prevent this by throwing a ReferenceError for undeclared variables.


Question 10: Functions Are Objects

What happens when we do this?

function bark() {
  console.log('Woof!');
}

bark.animal = 'dog';
  • A: Nothing, this is totally fine!
  • B: SyntaxError. You cannot add properties to a function this way.
  • C: "Woof" gets logged.
  • D: ReferenceError

Correct Answer: A

Explanation: Functions in JavaScript are objects. You can add properties to them just like any other object. The function itself is a special callable object with an invocable property.


Question 11: Prototype vs Constructor Properties

What’s the output?

function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

const member = new Person('Lydia', 'Hallie');
Person.getFullName = function() {
  return `${this.firstName} ${this.lastName}`;
};

console.log(member.getFullName());
  • A: TypeError
  • B: SyntaxError
  • C: Lydia Hallie
  • D: undefined undefined

Correct Answer: A

Explanation: Adding getFullName to the Person constructor function object does not make it available on instances. To make it available to all instances, you must add it to Person.prototype. As-is, member.getFullName is undefined, and calling it throws a TypeError.


Question 12: Constructor Without new

What’s the output?

function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

const lydia = new Person('Lydia', 'Hallie');
const sarah = Person('Sarah', 'Smith');

console.log(lydia);
console.log(sarah);
  • A: Person {firstName: "Lydia", lastName: "Hallie"} and undefined
  • B: Person {firstName: "Lydia", lastName: "Hallie"} and Person {firstName: "Sarah", lastName: "Smith"}
  • C: Person {firstName: "Lydia", lastName: "Hallie"} and {}
  • D: Person {firstName: "Lydia", lastName: "Hallie"} and ReferenceError

Correct Answer: A

Explanation: Without new, this refers to the global object (not a new instance). Person('Sarah', 'Smith') sets global.firstName = 'Sarah' and returns undefined. Always use new with constructor functions.


Question 13: Event Propagation Phases

What are the three phases of event propagation?

  • A: Target > Capturing > Bubbling
  • B: Bubbling > Target > Capturing
  • C: Target > Bubbling > Capturing
  • D: Capturing > Target > Bubbling

Correct Answer: D

Explanation: Event propagation has three phases: (1) Capturing — the event travels from the root down to the target element; (2) Target — the event reaches the target; (3) Bubbling — the event bubbles back up from the target to the root.


Question 14: Prototypes

All objects have prototypes.

  • A: true
  • B: false

Correct Answer: B

Explanation: All objects have prototypes except for the base object created by the user or with new. The base object has access to methods like .toString through the prototype chain. Object.create(null) creates an object with no prototype.


Question 15: Type Coercion in Addition

What’s the output?

function sum(a, b) {
  return a + b;
}

sum(1, '2');
  • A: NaN
  • B: TypeError
  • C: "12"
  • D: 3

Correct Answer: C

Explanation: JavaScript is dynamically typed. When adding a number and a string with +, the number is coerced to a string. 1 becomes "1", and "1" + "2" concatenates to "12".


Question 16: Postfix vs Prefix Increment

What’s the output?

let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
  • A: 1 1 2
  • B: 1 2 2
  • C: 0 2 2
  • D: 0 1 2

Correct Answer: C

Explanation: Postfix number++ returns the current value (0) then increments (now 1). Prefix ++number increments first (now 2) then returns the new value (2). Final value is 2.


Question 17: Tagged Template Literals

What’s the output?

function getPersonInfo(one, two, three) {
  console.log(one);
  console.log(two);
  console.log(three);
}

const person = 'Lydia';
const age = 21;

getPersonInfo`${person} is ${age} years old`;
  • A: "Lydia" 21 ["", " is ", " years old"]
  • B: ["", " is ", " years old"] "Lydia" 21
  • C: "Lydia" ["", " is ", " years old"] 21

Correct Answer: B

Explanation: With tagged template literals, the first argument is always an array of the string parts. The remaining arguments are the interpolated expression values. So one is ["", " is ", " years old"], two is "Lydia", and three is 21.


Question 18: Object Equality

What’s the output?

function checkAge(data) {
  if (data === { age: 18 }) {
    console.log('You are an adult!');
  } else if (data == { age: 18 }) {
    console.log('You are still an adult.');
  } else {
    console.log(`Hmm.. You don't have an age I guess`);
  }
}

checkAge({ age: 18 });
  • A: You are an adult!
  • B: You are still an adult.
  • C: Hmm.. You don't have an age I guess

Correct Answer: C

Explanation: Objects are compared by reference, not by value. The { age: 18 } passed as argument and the { age: 18 } in the comparison are different objects in memory. Both === and == return false for different object references.


Question 19: Rest Parameters

What’s the output?

function getAge(...args) {
  console.log(typeof args);
}

getAge(21);
  • A: "number"
  • B: "array"
  • C: "object"
  • D: "NaN"

Correct Answer: C

Explanation: The rest parameter ...args collects arguments into an array. Since arrays are objects in JavaScript, typeof args returns "object". There is no "array" type in JavaScript.


Question 20: Strict Mode

What’s the output?

function getAge() {
  'use strict';
  age = 21;
  console.log(age);
}

getAge();
  • A: 21
  • B: undefined
  • C: ReferenceError
  • D: TypeError

Correct Answer: C

Explanation: In strict mode, assigning a value to an undeclared variable throws a ReferenceError. Without strict mode, age = 21 would create a global variable. Strict mode prevents accidental global variable creation.


Question 21: eval()

What’s the value of sum?

const sum = eval('10*10+5');
  • A: 105
  • B: "105"
  • C: TypeError
  • D: "10*10+5"

Correct Answer: A

Explanation: eval() evaluates a string as JavaScript code. The expression 10 * 10 + 5 evaluates to the number 105. Note: eval() is generally discouraged for security and performance reasons.


Question 22: sessionStorage Lifetime

How long is cool_secret accessible?

sessionStorage.setItem('cool_secret', 123);
  • A: Forever, the data doesn’t get lost.
  • B: When the user closes the tab.
  • C: When the user closes the entire browser, not only the tab.
  • D: When the user shuts off their computer.

Correct Answer: B

Explanation: Data in sessionStorage is removed when the tab is closed. localStorage persists until explicitly cleared. Both are limited to the same origin (protocol + domain + port).


Question 23: var Redeclaration

What’s the output?

var num = 8;
var num = 10;

console.log(num);
  • A: 8
  • B: 10
  • C: SyntaxError
  • D: ReferenceError

Correct Answer: B

Explanation: With var, you can redeclare the same variable — the latest value wins. With let or const, redeclaration in the same scope throws a SyntaxError.


Question 24: Object Keys and Set

What’s the output?

const obj = { 1: 'a', 2: 'b', 3: 'c' };
const set = new Set([1, 2, 3, 4, 5]);

obj.hasOwnProperty('1');
obj.hasOwnProperty(1);
set.has('1');
set.has(1);
  • A: false true false true
  • B: false true true true
  • C: true true false true
  • D: true true true true

Correct Answer: C

Explanation: Object keys are always strings (or Symbols). obj.hasOwnProperty('1') and obj.hasOwnProperty(1) both return true because 1 is coerced to "1". Sets don’t do type coercion: set.has('1') is false (string), set.has(1) is true (number).


Question 25: Duplicate Object Keys

What’s the output?

const obj = { a: 'one', b: 'two', a: 'three' };
console.log(obj);
  • A: { a: "one", b: "two" }
  • B: { b: "two", a: "three" }
  • C: { a: "three", b: "two" }
  • D: SyntaxError

Correct Answer: C

Explanation: Duplicate keys are allowed — the last value wins, but the key retains its original position. So a stays in first position with value "three", and b follows with "two".


Question 26: Global Execution Context

The JavaScript global execution context creates two things for you: the global object, and the “this” keyword.

  • A: true
  • B: false
  • C: it depends

Correct Answer: A

Explanation: The global execution context creates: (1) the global object (window in browsers, global in Node.js), and (2) the this keyword bound to that global object (in non-strict mode).


Question 27: The continue Statement

What’s the output?

for (let i = 1; i < 5; i++) {
  if (i === 3) continue;
  console.log(i);
}
  • A: 1 2
  • B: 1 2 3
  • C: 1 2 4
  • D: 1 3 4

Correct Answer: C

Explanation: The continue statement skips the current iteration when i === 3. So 1, 2, and 4 are logged, but 3 is skipped.


Question 28: Extending Built-in Prototypes

What’s the output?

String.prototype.giveLydiaPizza = () => {
  return 'Just give Lydia pizza already!';
};

const name = 'Lydia';

console.log(name.giveLydiaPizza());
  • A: "Just give Lydia pizza already!"
  • B: TypeError: not a function
  • C: SyntaxError
  • D: undefined

Correct Answer: A

Explanation: String is a built-in constructor. Adding a method to String.prototype makes it available on all string instances. Primitive strings are auto-boxed to String objects when accessing properties, so name.giveLydiaPizza() works.


Question 29: Object Keys Are Stringified

What’s the output?

const a = {};
const b = { key: 'b' };
const c = { key: 'c' };

a[b] = 123;
a[c] = 456;

console.log(a[b]);
  • A: 123
  • B: 456
  • C: undefined
  • D: ReferenceError

Correct Answer: B

Explanation: Object keys must be strings (or Symbols). When you use an object as a key, it’s stringified to "[object Object]". Both b and c become the same key "[object Object]", so a[c] = 456 overwrites a[b] = 123. The result is 456.


Question 30: Event Loop

What’s the output?

const foo = () => console.log('First');
const bar = () => setTimeout(() => console.log('Second'));
const baz = () => console.log('Third');

bar();
foo();
baz();
  • A: First Second Third
  • B: First Third Second
  • C: Second First Third
  • D: Second Third First

Correct Answer: B

Explanation: bar() calls setTimeout, which pushes its callback to the Web API / task queue. foo() logs "First" synchronously. baz() logs "Third" synchronously. Only after the call stack is empty does the event loop push the setTimeout callback onto the stack, logging "Second" last.


Topics Covered (Questions 1-30)

TopicQuestions
Variable hoisting (var, let, const)1, 2, 23
this keyword and arrow functions3, 8, 12
Type coercion and operators4, 15, 16, 48
Object references and equality5, 6, 7, 18, 25, 29
Prototypes and constructors10, 11, 14, 28
Scope and closures9, 20, 21
Event propagation and event loop13, 30
ES6+ features17, 19, 24, 26, 27
Web APIs22

Part 2 (Questions 31-60) coming soon. Full course: 155 questions across 6 parts.

Source: lydiahallie/javascript-questions — licensed for educational use.

Published at: vorluxai.com/templates/javascript-quiz-course


Versión Española

Dominio de JavaScript: 155 Preguntas de Entrevista

Ponga a prueba sus conocimientos de JavaScript desde nivel básico hasta avanzado. Cada pregunta incluye opciones de respuesta múltiple, la respuesta correcta y una explicación detallada. Basado en lydiahallie/javascript-questions.

Esta es la Parte 1 (Preguntas 1-30). El curso completo contiene 155 preguntas organizadas por dificultad.


Nota sobre la traducción

Los bloques de código JavaScript permanecen en inglés (es el idioma del lenguaje de programación). Las instrucciones, explicaciones y opciones de respuesta están disponibles en la versión inglesa anterior. Los conceptos clave cubiertos son:

Temas Cubiertos

TemaPreguntas
Scope y hoisting1, 3, 7, 16, 20
Closures2, 8, 15, 25, 30
Prototipos y herencia4, 9, 14
Programación asíncrona5, 10, 22, 28, 29
Coerción de tipos6, 11, 13, 21, 23
Objetos y destructuring12, 18, 20
Funcionalidades ES6+17, 19, 24, 26, 27
APIs Web22

Cómo Usar Este Recurso

  1. Auto-evaluación: Intente responder cada pregunta antes de ver la respuesta
  2. Estudio por temas: Use la tabla de temas para enfocarse en áreas débiles
  3. Preparación de entrevistas: Las preguntas cubren los temas más frecuentes en entrevistas técnicas de JavaScript
  4. Formación de equipos: Use como material de evaluación para candidatos o para sesiones de aprendizaje en equipo

Niveles de Dificultad

NivelPreguntasDescripción
Básico1-10Fundamentos: scope, tipos, hoisting
Intermedio11-20Closures, prototipos, coerción
Avanzado21-30Event loop, promesas, generadores

Parte 2 (Preguntas 31-60) próximamente. Curso completo: 155 preguntas en 6 partes.

Fuente: lydiahallie/javascript-questions

¿Necesita evaluaciones técnicas personalizadas para su equipo? Contacte con VORLUX AI para formación a medida.

EU AI Act: 99 days to deadline

15 minutes to evaluate your case

No-commitment initial consultation. We analyze your infrastructure and recommend the optimal hybrid architecture.

No commitment 15 minutes Custom proposal

136 pages of free resources · 26 compliance templates · 22 certified devices