LearnThatStack Ace your next interview
Frontend Development

JavaScript.

Start free Change topic Change

Practise JavaScript one question at a time. Answer out loud or in writing, get graded, and see exactly what you missed.

Try one question

What are the primitive data types in JavaScript?

The answer

JavaScript has 7 primitive data types. A primitive is a value that is not an object, and it cannot be changed once it is created.

  1. Number, for integers and floating-point numbers.
  2. String, for text.
  3. Boolean, which is true or false.
  4. Undefined, the value of a variable that was declared but not assigned.
  5. Null, an intentional absence of value.
  6. Symbol, a unique identifier added in ES6.
  7. BigInt, for integers beyond Number.MAX_SAFE_INTEGER, added in ES2020.

Arrays, functions and every other value are objects. typeof null returns "object", a legacy bug kept for compatibility.

Example · what grading looks like
What is hoisting in JavaScript?

“Hoisting is when JavaScript moves declarations to the top of their scope before the code runs. So if you use a var before the line where it's declared, you get undefined instead of an error. let and const aren't hoisted, so using them before the declaration throws a ReferenceError.”

Partly there

The var behavior and the ReferenceError are right. But saying let and const aren't hoisted is wrong, and it misses why the error happens: the temporal dead zone.

Wrong: Says let and const aren't hoisted. They are hoisted but left uninitialized, which is why the early read throws instead of finding an outer variable.

Missed: No mention of the temporal dead zone, the span between scope start and the declaration where let and const can't be read.

Missed: Doesn't cover function declarations, which are hoisted whole and can be called before their definition.

Missed: Says declarations "move" to the top, but nothing moves in the source. The engine sets up declarations before running the scope.


Get your own answers graded

Sign up free. Your account comes with 50 credits for grading, and it remembers what you missed.

What it covers

All 126 questions

Each on its own page

Types, equality and coercion

Primitive types and how values are passed, null versus undefined, checking types, loose and strict equality, falsy values, floating-point numbers and how JavaScript converts between types.

11 questions

  1. What are the primitive data types in JavaScript?
  2. What is the difference between null and undefined?
  3. How do you check the type of a variable in JavaScript?
  4. Explain the difference between == and ===
  5. What are falsy values in JavaScript? Pro
  6. What is type coercion in JavaScript? Pro
  7. What are symbols in JavaScript? Pro
  8. What is BigInt? Pro
  9. What is the difference between deep and shallow equality? Pro
  10. Is JavaScript pass by value or pass by reference? Pro
  11. Why is 0.1 + 0.2 not equal to 0.3 in JavaScript? Pro

Scope, hoisting and closures

How var, let and const differ, global, function and block scope, hoisting and the temporal dead zone, closures, strict mode and the execution context.

11 questions

  1. What is the difference between let, var, and const?
  2. What is hoisting in JavaScript?
  3. Explain the concept of "use strict" in JavaScript
  4. What is scope in JavaScript?
  5. What is the difference between undefined and not defined? Pro
  6. What is a closure in JavaScript? Pro
  7. Explain lexical scoping in JavaScript Pro
  8. What is the temporal dead zone? Pro
  9. What is the with statement and why should you avoid it? Pro
  10. Why does setTimeout in a var loop log the same value every time? Pro
  11. What is the execution context in JavaScript? Pro

Operators and modern syntax

Template literals, destructuring, spread and rest, optional chaining, nullish coalescing, short-circuit logic and loop forms like for...in and for...of.

11 questions

  1. What are template literals? Pro
  2. What is the ternary operator? Pro
  3. What is the comma operator? Pro
  4. What is destructuring assignment? Pro
  5. What is the spread operator? Pro
  6. What is the rest parameter? Pro
  7. What is the nullish coalescing operator? Pro
  8. What is optional chaining? Pro
  9. What is the difference between for...in and for...of? Pro
  10. What is short-circuit evaluation? Pro
  11. What are tagged templates in JavaScript? Pro

Functions and this binding

Ways to declare functions, IIFEs, arrow functions compared with regular ones, how this is set, the arguments object, call, apply and bind, and recursion limits.

10 questions

  1. What are the different ways to declare a function in JavaScript?
  2. What are default parameters? Pro
  3. What is the difference between function declarations and function expressions? Pro
  4. What are arrow functions and how do they differ from regular functions? Pro
  5. What is the arguments object and what are its limitations? Pro
  6. What is the difference between call, apply, and bind? Pro
  7. What is stack overflow in JavaScript? Pro
  8. How does the this keyword work in JavaScript? Pro
  9. What is an IIFE and why would you use one? Pro
  10. What is recursion and how do you optimize it? Pro

DOM and events

Selecting, creating and changing DOM elements, attributes versus properties, event handlers, bubbling, capturing and delegation, watching the DOM for changes, and how scripts and the page load.

13 questions

  1. What is the DOM?
  2. How do you select elements from the DOM?
  3. What is the difference between innerHTML, textContent, and innerText?
  4. How do you create and append elements to the DOM?
  5. What are the different ways to handle events in JavaScript?
  6. How do you prevent default behavior and stop event propagation? Pro
  7. What is event delegation? Pro
  8. What is event bubbling and event capturing? Pro
  9. What is the difference between target and currentTarget in events? Pro
  10. What is the difference between async and defer on a script tag? Pro
  11. What is the difference between an attribute and a property in the DOM? Pro
  12. What is the difference between the load and DOMContentLoaded events? Pro
  13. What is the MutationObserver API? Pro

Objects, prototypes and classes

Creating and copying objects, the prototype chain, the new operator, classes and private fields, getters and setters, freezing objects, method chaining and why not to extend built-ins.

14 questions

  1. How do you create objects in JavaScript?
  2. What is the difference between dot notation and bracket notation?
  3. How do you copy objects in JavaScript? Pro
  4. What is a prototype in JavaScript? Pro
  5. What is the difference between __proto__ and prototype? Pro
  6. How does prototypal inheritance work? Pro
  7. What is the new operator and how does it work? Pro
  8. What are classes in JavaScript? Pro
  9. What is the difference between Object.freeze(), Object.seal(), and Object.preventExtensions()? Pro
  10. What is the difference between Object.create() and constructor functions? Pro
  11. What is method chaining and how do you implement it? Pro
  12. What are getters and setters in JavaScript? Pro
  13. Why is extending built-in JavaScript objects not a good idea? Pro
  14. What are private class fields in JavaScript? Pro

Async code and error handling

try/catch and custom errors, callbacks, promises and async/await, the call stack, the event loop, and how microtasks and macrotasks are ordered.

13 questions

  1. How do you handle errors in JavaScript? Pro
  2. What are the different types of errors in JavaScript? Pro
  3. What are callbacks and what is callback hell? Pro
  4. What are Promises in JavaScript? Pro
  5. What is the difference between Promise.all() and Promise.allSettled()? Pro
  6. What is async/await? Pro
  7. How do you create custom errors? Pro
  8. How do you handle errors in async/await? Pro
  9. What is the call stack? Pro
  10. What are the different ways to handle asynchronous operations? Pro
  11. What is the difference between Promise.race() and Promise.any()? Pro
  12. What is the event loop in JavaScript? Pro
  13. What is the difference between microtasks and macrotasks? Pro

Browser APIs, storage and network

JSON, localStorage, sessionStorage and cookies, fetch, cancelling requests and CORS, observers and animation frames, and web and service workers.

11 questions

  1. What is JSON and how do you work with it? Pro
  2. What is localStorage and sessionStorage? Pro
  3. What are cookies in JavaScript? Pro
  4. What is the Intersection Observer API? Pro
  5. What is requestAnimationFrame? Pro
  6. What is the Fetch API? Pro
  7. What is CORS? Pro
  8. What is the difference between localStorage, sessionStorage, and cookies? Pro
  9. How do you cancel a fetch request with AbortController? Pro
  10. What are Web Workers? Pro
  11. What is a service worker? Pro

Functional programming

Higher-order functions, array methods such as map, filter, reduce, forEach, slice and splice, pure functions, immutability, currying, composition and memoization.

10 questions

  1. What is the difference between forEach and map? Pro
  2. What is the difference between slice and splice? Pro
  3. What are array methods in JavaScript? Explain map, filter, and reduce Pro
  4. What are higher-order functions? Pro
  5. What is memoization? Pro
  6. What are pure functions? Pro
  7. What is immutability in JavaScript? Pro
  8. What is functional programming in JavaScript? Pro
  9. Explain the concept of currying in JavaScript Pro
  10. What is function composition? Pro

Collections, iterators and metaprogramming

Map, Set, WeakMap and WeakSet, the iteration protocol and generators, property flags and descriptors, and catching object operations with Proxy and Reflect.

7 questions

  1. What are Maps and Sets? Pro
  2. What are property flags and descriptors in JavaScript? Pro
  3. What are iterators and iterables? Pro
  4. What are generators in JavaScript? Pro
  5. What is a WeakMap and WeakSet? Pro
  6. What is a Proxy in JavaScript? Pro
  7. What is Reflect in JavaScript? Pro

Modules, tooling and performance

ES modules and CommonJS, dynamic imports, tree shaking, polyfills and transpiling, lazy loading, debouncing and throttling, and memory management.

10 questions

  1. What is debouncing and throttling? Pro
  2. What is lazy loading? Pro
  3. What are some JavaScript performance best practices? Pro
  4. What is the module system in JavaScript? Pro
  5. What is tree shaking? Pro
  6. What is the difference between CommonJS and ES6 modules? Pro
  7. What is a polyfill? Pro
  8. What is transpilation? Pro
  9. What is memory management in JavaScript? Pro
  10. What are dynamic imports in JavaScript? Pro

Design patterns

Common JavaScript design patterns such as module, singleton, factory and observer, and when each one fits.

5 questions

  1. What is the Observer pattern in JavaScript? Pro
  2. What is the Module pattern? Pro
  3. What is the Singleton pattern in JavaScript? Pro
  4. What is the Factory pattern? Pro
  5. What are commonly used JavaScript design patterns? Pro
Practice · Questions

All questions

Showing of 126
Beginner 36
01

What is the difference between let, var, and const?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

var is function-scoped, while let and const are block-scoped. const also stops the variable from being reassigned.

var can be redeclared and updated. It is hoisted and starts as undefined, so reading it before its line gives undefined instead of an error.

let can be updated but not redeclared in the same scope. It is hoisted but not initialized, so reading it before its declaration throws a ReferenceError.

const can be neither updated nor redeclared, and it must be initialized where it is declared. It fixes the binding, not the value, so an object held in a const can still change.

var a = 1;     // Function scoped
let b = 2;     // Block scoped
const c = 3;   // Block scoped, immutable binding
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is hoisting in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Hoisting means JavaScript sets up a scope's declarations before it runs any code in that scope. The code then behaves as if the declarations moved to the top, although nothing moves in the source.

Variables declared with var are hoisted and initialized with undefined. Variables declared with let and const are hoisted but not initialized, so reading one before its declaration throws a ReferenceError. That stretch is called the temporal dead zone. Function declarations are hoisted whole, so you can call them before the line that defines them.

console.log(x); // undefined (not error)
var x = 5;
console.log(y); // ReferenceError
let y = 10;
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

Explain the concept of "use strict" in JavaScript

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

"use strict" turns on strict mode, which makes JavaScript throw errors for mistakes it would otherwise ignore and blocks a few unsafe actions. You put it at the top of a script or a function.

In strict mode:

  • Assigning to an undeclared variable throws instead of creating a global.
  • Duplicate parameter names are a syntax error.
  • this is undefined in a plain function call, not the global object.
  • Deleting a variable, a function or arguments is not allowed.

These rules make code safer and easier for engines to optimize. Modules and class bodies are strict automatically, with no directive needed.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What are the different ways to declare a function in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The main ways are a function declaration, a function expression and an arrow function. The Function constructor also works but is rarely used.

  • A declaration is hoisted whole, so you can call it before its line.
  • An expression assigns a function to a variable, so it exists only after that line runs.
  • An arrow function is a shorter expression that takes this from the surrounding code.
  • The Function constructor builds a function from a string at runtime.
// Function declaration
function myFunction() { }
// Function expression
const myFunction2 = function() { };
// Arrow function
const myFunction3 = () => { };
// Function constructor (rarely used)
const myFunction4 = new Function('return 1');
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What are the primitive data types in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

JavaScript has 7 primitive data types. A primitive is a value that is not an object, and it cannot be changed once it is created.

  1. Number, for integers and floating-point numbers.
  2. String, for text.
  3. Boolean, which is true or false.
  4. Undefined, the value of a variable that was declared but not assigned.
  5. Null, an intentional absence of value.
  6. Symbol, a unique identifier added in ES6.
  7. BigInt, for integers beyond Number.MAX_SAFE_INTEGER, added in ES2020.

Arrays, functions and every other value are objects. typeof null returns "object", a legacy bug kept for compatibility.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What is the difference between null and undefined?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

undefined means a value was never assigned, while null is an explicit "no value". JavaScript produces undefined on its own, and null comes from your code or from APIs such as document.getElementById() when nothing matches.

A variable that is declared but not assigned is undefined, and so is a function parameter the caller did not provide. A missing object property and a function with no return also give undefined. null is an intentional assignment that marks a value as empty.

The two are loosely equal but not strictly equal, so null == undefined is true and null === undefined is false. typeof undefined is "undefined", but typeof null is "object", a legacy quirk.

let a; // undefined
let b = null; // null
typeof undefined; // "undefined"
typeof null;      // "object" (legacy quirk)
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

How do you check the type of a variable in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Use typeof for primitives and functions, Array.isArray() for arrays, and instanceof to check whether an object came from a given constructor or class.

typeof returns a string such as "number", "string" or "function". It has two traps. typeof null is "object", and so is typeof of any array, which is why arrays need Array.isArray(). To test for null itself, compare with === null.

instanceof walks the prototype chain, so it fails for objects created in another frame or window.

The most reliable general check is Object.prototype.toString.call(value), which returns labels such as "[object Date]" or "[object Null]".

typeof variable;           // Returns string representation
Array.isArray(variable);   // Check if array
variable instanceof Constructor; // Check instance type
Object.prototype.toString.call(variable); // Most reliable method
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

Explain the difference between == and ===

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

=== compares value and type with no conversion, while == converts both sides to a common type and then compares. That conversion is called type coercion.

With loose equality, 5 == "5" is true because the string becomes a number first. With strict equality, 5 === "5" is false because a number and a string are different types. A special case is null == undefined, which is true, while null === undefined is false.

The coercion rules are hard to predict, so use === by default. The one common exception is value == null, which checks for null and undefined together.

5 == "5";    // true (coercion)
5 === "5";   // false (different types)
null == undefined;  // true
null === undefined; // false
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

How do you create objects in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The usual way is an object literal, such as { name: "John" }. You can also call new Object(), use Object.create() to choose the new object's prototype, or call a constructor function with new.

  • An object literal is the shortest form and covers most cases.
  • new Object() does the same thing with more code, so it is rarely used.
  • Object.create(proto) makes an object whose prototype is proto, and Object.create(null) makes one with no prototype at all, which suits a plain dictionary.
  • A constructor function called with new builds many objects of the same shape, which is what the class syntax does today.
// Object literal
const obj1 = { name: "John", age: 30 };
// Object constructor
const obj2 = new Object();
obj2.name = "John";
// Object.create()
const obj3 = Object.create(null);
// Constructor function
function Person(name) { this.name = name; }
const obj4 = new Person("John");
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

10

What is the difference between dot notation and bracket notation?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Dot notation reads a property whose name is a valid identifier, while bracket notation takes any string or a variable as the key.

Use dot notation, as in obj.name, whenever the key is fixed and a valid identifier. It is shorter and easier to read. Use bracket notation, as in obj["full name"], when the key has spaces or special characters. A key that starts with a digit needs it too.

Brackets also take an expression, so obj[key] reads whatever property the variable key names at runtime. That makes bracket notation the only choice for dynamic keys, such as when looping over property names.

const obj = { name: "John", "full name": "John Doe" };
obj.name;           // Dot notation
obj["full name"];   // Bracket notation
obj[variable];      // Dynamic access
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

11

What is scope in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Scope decides where in the code a variable or function can be accessed. JavaScript has three main levels.

A variable in the global scope, declared outside any function or block, is accessible everywhere. A var or a parameter has function scope, accessible anywhere in its function. A let or const has block scope, accessible only inside the nearest braces. So a var inside an if block still belongs to the whole function, while a let there cannot be read once the block ends.

Scopes nest, so JavaScript resolves a name by checking the current scope first and then each outer scope. That lookup is the scope chain. Keep globals few, because every script on the page shares them and their names can clash.

var globalVar = "global";
function example() {
  var functionScoped = "function";
  if (true) {
    let blockScoped = "block";
    const alsoBlock = "block";
  }
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

12

What is the DOM?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

The Document Object Model (DOM) is the programming interface for an HTML document. It represents the page as a tree of objects that JavaScript can read and change.

The browser parses the HTML and builds a node for each element, attribute and piece of text. The document object is the root of that tree. Scripts start from it to find and change nodes, or to add and remove them, and the screen updates to match.

The DOM is not the HTML source. It reflects the page as it is now, including every change made by scripts.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

13

How do you select elements from the DOM?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Use querySelector() for the first element that matches a CSS selector, and querySelectorAll() for every match. The older getElementById(), getElementsByClassName() and getElementsByTagName() each select by one thing.

querySelector() returns the first match, or null if nothing matches. querySelectorAll() returns a static NodeList that does not change afterwards. Both accept any CSS selector, such as #myId .myClass, which makes them the most flexible choice.

getElementById() is the direct way to find a single element by its ID. getElementsByClassName() and getElementsByTagName() return a live HTMLCollection, which updates by itself as the DOM changes. That can surprise you in a loop that adds or removes matching elements.

// By ID
document.getElementById('myId');
// By class
document.getElementsByClassName('myClass');
document.querySelector('.myClass');
document.querySelectorAll('.myClass');
// By tag
document.getElementsByTagName('div');
// By CSS selector
document.querySelector('#myId .myClass');
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

14

What is the difference between innerHTML, textContent, and innerText?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

innerHTML gets and sets HTML markup, textContent gets and sets raw text, and innerText gets and sets only the text a user can see.

  • innerHTML parses what you assign as HTML, so '<b>Bold</b>' renders as bold text. Never assign untrusted input to it, because that opens the page to cross-site scripting.
  • textContent treats everything as plain text, so the same string shows the tags literally. It ignores styling and returns the text of every node, including hidden elements and <script> content.
  • innerText respects CSS, so it skips hidden elements. Reading it forces the browser to calculate layout, which makes it slower.

For plain text, textContent is the safe default.

element.innerHTML = '<b>Bold</b>';    // Renders as bold
element.textContent = '<b>Bold</b>';  // Shows literal text
element.innerText = 'Visible text';   // Respects CSS display
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

15

How do you create and append elements to the DOM?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Create the element with document.createElement(), set its content and attributes, then insert it with append(), appendChild() or insertAdjacentElement(). Until you insert it, the element exists only in memory.

  • appendChild() adds one node as the last child and returns that node.
  • append() is newer and takes several nodes or plain strings at once, but returns nothing.
  • insertAdjacentElement() takes a position such as 'beforeend', so you can place the element before, inside or after the target.

Set text with textContent rather than innerHTML, so user data is never parsed as HTML. When adding many elements, build them in a DocumentFragment and insert it once.

// Create element
const div = document.createElement('div');
div.textContent = 'Hello';
div.className = 'my-class';
// Append to DOM
document.body.appendChild(div);
// or
document.body.append(div);
// or
document.body.insertAdjacentElement('beforeend', div);
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

16

What are the different ways to handle events in JavaScript?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

There are three ways: an inline HTML attribute such as onclick, a DOM property such as button.onclick, and addEventListener(). Use addEventListener() in modern code.

An inline attribute mixes JavaScript into the HTML as a string, and a strict Content Security Policy (CSP) blocks it. A DOM property keeps the code in JavaScript, but each element holds only one handler per event, so assigning a second one replaces the first.

addEventListener() lets you attach many listeners to the same event. It also accepts options such as once and passive, supports the capture phase, and pairs with removeEventListener() for cleanup.

<!-- HTML attribute -->
<button onclick="handleClick()">Click</button>
// DOM property
button.onclick = function() { };
// addEventListener (recommended)
button.addEventListener('click', function() { });
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

17

How do you prevent default behavior and stop event propagation?

Part of Pro
18

What are template literals?

Part of Pro
19

What are default parameters?

Part of Pro
20

How do you handle errors in JavaScript?

Part of Pro
21

What is JSON and how do you work with it?

Part of Pro
22

What is localStorage and sessionStorage?

Part of Pro
23

What are cookies in JavaScript?

Part of Pro
24

What is the difference between undefined and not defined?

Part of Pro
25

What are falsy values in JavaScript?

Part of Pro
26

What is the ternary operator?

Part of Pro
27

What is the difference between forEach and map?

Part of Pro
28

What is the difference between slice and splice?

Part of Pro
29

What is the comma operator?

Part of Pro
30

What are array methods in JavaScript? Explain map, filter, and reduce

Part of Pro
31

What is destructuring assignment?

Part of Pro
32

What is the spread operator?

Part of Pro
33

What is the rest parameter?

Part of Pro
34

What is the nullish coalescing operator?

Part of Pro
35

What is optional chaining?

Part of Pro
36

What are the different types of errors in JavaScript?

Part of Pro
Intermediate 84
37

What is type coercion in JavaScript?

Part of Pro
38

What is the difference between function declarations and function expressions?

Part of Pro
39

What are arrow functions and how do they differ from regular functions?

Part of Pro Visual
40

What are higher-order functions?

Part of Pro
41

What is the arguments object and what are its limitations?

Part of Pro
42

How do you copy objects in JavaScript?

Part of Pro Visual
43

What is a closure in JavaScript?

Part of Pro
44

Explain lexical scoping in JavaScript

Part of Pro Visual
45

What is the temporal dead zone?

Part of Pro Visual
46

What is a prototype in JavaScript?

Part of Pro Visual
47

What is the difference between __proto__ and prototype?

Part of Pro Visual
48

How does prototypal inheritance work?

Part of Pro Visual
49

What is the new operator and how does it work?

Part of Pro
50

What are callbacks and what is callback hell?

Part of Pro
51

What are Promises in JavaScript?

Part of Pro
52

What is the difference between Promise.all() and Promise.allSettled()?

Part of Pro Visual
53

What is async/await?

Part of Pro
54

What is event delegation?

Part of Pro
55

What is event bubbling and event capturing?

Part of Pro Visual
56

What is the difference between target and currentTarget in events?

Part of Pro
57

What are classes in JavaScript?

Part of Pro
58

What are symbols in JavaScript?

Part of Pro
59

What are Maps and Sets?

Part of Pro
60

How do you create custom errors?

Part of Pro
61

How do you handle errors in async/await?

Part of Pro
62

What is debouncing and throttling?

Part of Pro Visual
63

What is memoization?

Part of Pro
64

What is lazy loading?

Part of Pro
65

What are some JavaScript performance best practices?

Part of Pro
66

What is the difference between call, apply, and bind?

Part of Pro
67

What is the module system in JavaScript?

Part of Pro
68

What is tree shaking?

Part of Pro
69

What is the difference between CommonJS and ES6 modules?

Part of Pro Visual
70

What is the Intersection Observer API?

Part of Pro Visual
71

What is requestAnimationFrame?

Part of Pro Visual
72

What is the Fetch API?

Part of Pro
73

What is CORS?

Part of Pro Visual
74

What is the difference between localStorage, sessionStorage, and cookies?

Part of Pro
75

What is a polyfill?

Part of Pro
76

What is transpilation?

Part of Pro
77

What is the difference between for...in and for...of?

Part of Pro
78

What is short-circuit evaluation?

Part of Pro
79

What is BigInt?

Part of Pro
80

What is the with statement and why should you avoid it?

Part of Pro
81

What is memory management in JavaScript?

Part of Pro
82

What are pure functions?

Part of Pro
83

What is immutability in JavaScript?

Part of Pro Visual
84

What is the difference between deep and shallow equality?

Part of Pro
85

What is the difference between Object.freeze(), Object.seal(), and Object.preventExtensions()?

Part of Pro
86

What is the difference between Object.create() and constructor functions?

Part of Pro
87

What is method chaining and how do you implement it?

Part of Pro
88

What is the call stack?

Part of Pro Visual
89

What is stack overflow in JavaScript?

Part of Pro
90

What are the different ways to handle asynchronous operations?

Part of Pro
91

How does the this keyword work in JavaScript?

Part of Pro Visual
92

What is the difference between async and defer on a script tag?

Part of Pro
93

What is an IIFE and why would you use one?

Part of Pro
94

What is the difference between an attribute and a property in the DOM?

Part of Pro
95

How do you cancel a fetch request with AbortController?

Part of Pro
96

What are getters and setters in JavaScript?

Part of Pro
97

Why is extending built-in JavaScript objects not a good idea?

Part of Pro
98

What are property flags and descriptors in JavaScript?

Part of Pro
99

What is the difference between the load and DOMContentLoaded events?

Part of Pro
100

What is functional programming in JavaScript?

Part of Pro
101

What are tagged templates in JavaScript?

Part of Pro Visual
102

Explain the concept of currying in JavaScript

Part of Pro
103

What is function composition?

Part of Pro
104

What is the Observer pattern in JavaScript?

Part of Pro
105

What is the Module pattern?

Part of Pro
106

What is the Singleton pattern in JavaScript?

Part of Pro
107

What is the Factory pattern?

Part of Pro
108

What are iterators and iterables?

Part of Pro
109

What are commonly used JavaScript design patterns?

Part of Pro
110

What are generators in JavaScript?

Part of Pro Visual
111

What are dynamic imports in JavaScript?

Part of Pro
112

What is the MutationObserver API?

Part of Pro Visual
113

What are Web Workers?

Part of Pro
114

What are private class fields in JavaScript?

Part of Pro
115

What is recursion and how do you optimize it?

Part of Pro Visual
116

Is JavaScript pass by value or pass by reference?

Part of Pro
117

Why is 0.1 + 0.2 not equal to 0.3 in JavaScript?

Part of Pro
118

What is the difference between Promise.race() and Promise.any()?

Part of Pro
119

Why does setTimeout in a var loop log the same value every time?

Part of Pro Visual
120

What is a WeakMap and WeakSet?

Part of Pro Visual
Expert 6
121

What is the event loop in JavaScript?

Part of Pro
122

What is the difference between microtasks and macrotasks?

Part of Pro Visual
123

What is a Proxy in JavaScript?

Part of Pro
124

What is Reflect in JavaScript?

Part of Pro
125

What is a service worker?

Part of Pro Visual
126

What is the execution context in JavaScript?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for JavaScript? Send them this set.
Quick recap

JavaScript in pictures.

A quick recap of JavaScript in 39 short animated pictures, one idea at a time. About 10 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 34 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

110 of 126 JavaScript answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git