Practise JavaScript one question at a time. Answer out loud or in writing, get graded, and see exactly what you missed.
What are the primitive data types in JavaScript?
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.
- Number, for integers and floating-point numbers.
- String, for text.
- Boolean, which is
trueorfalse. - Undefined, the value of a variable that was declared but not assigned.
- Null, an intentional absence of value.
- Symbol, a unique identifier added in ES6.
- 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.
Missed:
“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 thereThe 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
- Types, equality and coercion
- Scope, hoisting and closures
- Operators and modern syntax
- Functions and this binding
- DOM and events
- Objects, prototypes and classes
- Async code and error handling
- Browser APIs, storage and network
- Functional programming
- Collections, iterators and metaprogramming
- Modules, tooling and performance
- Design patterns
All 126 questions
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.
- What are the primitive data types in JavaScript?
-
What is the difference between
nullandundefined? - How do you check the type of a variable in JavaScript?
-
Explain the difference between
==and=== - What are falsy values in JavaScript? Pro
- What is type coercion in JavaScript? Pro
- What are symbols in JavaScript? Pro
- What is BigInt? Pro
- What is the difference between deep and shallow equality? Pro
- Is JavaScript pass by value or pass by reference? Pro
- 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.
-
What is the difference between
let,var, andconst? - What is hoisting in JavaScript?
- Explain the concept of "use strict" in JavaScript
- What is scope in JavaScript?
-
What is the difference between
undefinedandnot defined? Pro - What is a closure in JavaScript? Pro
- Explain lexical scoping in JavaScript Pro
- What is the temporal dead zone? Pro
-
What is the
withstatement and why should you avoid it? Pro - Why does setTimeout in a var loop log the same value every time? Pro
- 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.
- What are template literals? Pro
- What is the ternary operator? Pro
- What is the comma operator? Pro
- What is destructuring assignment? Pro
- What is the spread operator? Pro
- What is the rest parameter? Pro
- What is the nullish coalescing operator? Pro
- What is optional chaining? Pro
-
What is the difference between
for...inandfor...of? Pro - What is short-circuit evaluation? Pro
- 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.
- What are the different ways to declare a function in JavaScript?
- What are default parameters? Pro
- What is the difference between function declarations and function expressions? Pro
- What are arrow functions and how do they differ from regular functions? Pro
-
What is the
argumentsobject and what are its limitations? Pro -
What is the difference between
call,apply, andbind? Pro - What is stack overflow in JavaScript? Pro
- How does the this keyword work in JavaScript? Pro
- What is an IIFE and why would you use one? Pro
- 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.
- What is the DOM?
- How do you select elements from the DOM?
-
What is the difference between
innerHTML,textContent, andinnerText? - How do you create and append elements to the DOM?
- What are the different ways to handle events in JavaScript?
- How do you prevent default behavior and stop event propagation? Pro
- What is event delegation? Pro
- What is event bubbling and event capturing? Pro
-
What is the difference between
targetandcurrentTargetin events? Pro - What is the difference between async and defer on a script tag? Pro
- What is the difference between an attribute and a property in the DOM? Pro
- What is the difference between the load and DOMContentLoaded events? Pro
- 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.
- How do you create objects in JavaScript?
- What is the difference between dot notation and bracket notation?
- How do you copy objects in JavaScript? Pro
- What is a prototype in JavaScript? Pro
-
What is the difference between
__proto__andprototype? Pro - How does prototypal inheritance work? Pro
-
What is the
newoperator and how does it work? Pro - What are classes in JavaScript? Pro
-
What is the difference between
Object.freeze(),Object.seal(), andObject.? Proprevent Extensions() -
What is the difference between
Object.create()and constructor functions? Pro - What is method chaining and how do you implement it? Pro
- What are getters and setters in JavaScript? Pro
- Why is extending built-in JavaScript objects not a good idea? Pro
- 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.
- How do you handle errors in JavaScript? Pro
- What are the different types of errors in JavaScript? Pro
- What are callbacks and what is callback hell? Pro
- What are Promises in JavaScript? Pro
-
What is the difference between
Promise.all()andPromise.? Proall Settled() - What is async/await? Pro
- How do you create custom errors? Pro
- How do you handle errors in async/await? Pro
- What is the call stack? Pro
- What are the different ways to handle asynchronous operations? Pro
- What is the difference between Promise.race() and Promise.any()? Pro
- What is the event loop in JavaScript? Pro
- 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.
- What is JSON and how do you work with it? Pro
- What is localStorage and sessionStorage? Pro
- What are cookies in JavaScript? Pro
- What is the Intersection Observer API? Pro
-
What is
request? ProAnimation Frame - What is the Fetch API? Pro
- What is CORS? Pro
- What is the difference between localStorage, sessionStorage, and cookies? Pro
- How do you cancel a fetch request with AbortController? Pro
- What are Web Workers? Pro
- 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.
- What is the difference between forEach and map? Pro
- What is the difference between slice and splice? Pro
- What are array methods in JavaScript? Explain map, filter, and reduce Pro
- What are higher-order functions? Pro
- What is memoization? Pro
- What are pure functions? Pro
- What is immutability in JavaScript? Pro
- What is functional programming in JavaScript? Pro
- Explain the concept of currying in JavaScript Pro
- 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.
Modules, tooling and performance
ES modules and CommonJS, dynamic imports, tree shaking, polyfills and transpiling, lazy loading, debouncing and throttling, and memory management.
- What is debouncing and throttling? Pro
- What is lazy loading? Pro
- What are some JavaScript performance best practices? Pro
- What is the module system in JavaScript? Pro
- What is tree shaking? Pro
- What is the difference between CommonJS and ES6 modules? Pro
- What is a polyfill? Pro
- What is transpilation? Pro
- What is memory management in JavaScript? Pro
- 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.
All questions
Showing of 126What is the difference between let, var, and const?
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:
Last attempt -
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
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 ↓
What is hoisting in JavaScript?
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:
Last attempt -
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;
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 ↓
Explain the concept of "use strict" in JavaScript
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:
Last attempt -
"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.
thisisundefinedin a plain function call, not the global object.- Deleting a variable, a function or
argumentsis not allowed.
These rules make code safer and easier for engines to optimize. Modules and class bodies are strict automatically, with no directive needed.
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 ↓
What are the different ways to declare a function in JavaScript?
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:
Last attempt -
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
thisfrom the surrounding code. - The
Functionconstructor 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');
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 ↓
What are the primitive data types in JavaScript?
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:
Last attempt -
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.
- Number, for integers and floating-point numbers.
- String, for text.
- Boolean, which is
trueorfalse. - Undefined, the value of a variable that was declared but not assigned.
- Null, an intentional absence of value.
- Symbol, a unique identifier added in ES6.
- 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.
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 ↓
What is the difference between null and undefined?
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:
Last attempt -
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)
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 ↓
How do you check the type of a variable in JavaScript?
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:
Last attempt -
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
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 ↓
Explain the difference between == and ===
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:
Last attempt -
=== 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
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 ↓
How do you create objects in JavaScript?
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:
Last attempt -
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 isproto, andObject.create(null)makes one with no prototype at all, which suits a plain dictionary.- A constructor function called with
newbuilds many objects of the same shape, which is what theclasssyntax 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");
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 ↓
What is the difference between dot notation and bracket notation?
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:
Last attempt -
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
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 ↓
What is scope in JavaScript?
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:
Last attempt -
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";
}
}
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 ↓
What is the DOM?
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:
Last attempt -
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.
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 ↓
How do you select elements from the DOM?
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:
Last attempt -
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');
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 ↓
What is the difference between innerHTML, textContent, and innerText?
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:
Last attempt -
innerHTML gets and sets HTML markup, textContent gets and sets raw text, and innerText gets and sets only the text a user can see.
innerHTMLparses 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.textContenttreats 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.innerTextrespects 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
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 ↓
How do you create and append elements to the DOM?
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:
Last attempt -
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);
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 ↓
What are the different ways to handle events in JavaScript?
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:
Last attempt -
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() { });
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 ↓
How do you prevent default behavior and stop event propagation?
What are template literals?
What are default parameters?
How do you handle errors in JavaScript?
What is JSON and how do you work with it?
What is localStorage and sessionStorage?
What are cookies in JavaScript?
What is the difference between undefined and not defined?
What are falsy values in JavaScript?
What is the ternary operator?
What is the difference between forEach and map?
What is the difference between slice and splice?
What is the comma operator?
What are array methods in JavaScript? Explain map, filter, and reduce
What is destructuring assignment?
What is the spread operator?
What is the rest parameter?
What is the nullish coalescing operator?
What is optional chaining?
What are the different types of errors in JavaScript?
What is type coercion in JavaScript?
What is the difference between function declarations and function expressions?
What are arrow functions and how do they differ from regular functions?
What are higher-order functions?
What is the arguments object and what are its limitations?
How do you copy objects in JavaScript?
What is a closure in JavaScript?
Explain lexical scoping in JavaScript
What is the temporal dead zone?
What is a prototype in JavaScript?
What is the difference between __proto__ and prototype?
How does prototypal inheritance work?
What is the new operator and how does it work?
What are callbacks and what is callback hell?
What are Promises in JavaScript?
What is the difference between Promise.all() and Promise.allSettled() ?
What is async/await?
What is event delegation?
What is event bubbling and event capturing?
What is the difference between target and currentTarget in events?
What are classes in JavaScript?
What are symbols in JavaScript?
What are Maps and Sets?
How do you create custom errors?
How do you handle errors in async/await?
What is debouncing and throttling?
What is memoization?
What is lazy loading?
What are some JavaScript performance best practices?
What is the difference between call, apply, and bind?
What is the module system in JavaScript?
What is tree shaking?
What is the difference between CommonJS and ES6 modules?
What is the Intersection Observer API?
What is requestAnimationFrame ?
What is the Fetch API?
What is CORS?
What is the difference between localStorage, sessionStorage, and cookies?
What is a polyfill?
What is transpilation?
What is the difference between for...in and for...of?
What is short-circuit evaluation?
What is BigInt?
What is the with statement and why should you avoid it?
What is memory management in JavaScript?
What are pure functions?
What is immutability in JavaScript?
What is the difference between deep and shallow equality?
What is the difference between Object.freeze(), Object.seal(), and Object.preventExtensions() ?
What is the difference between Object.create() and constructor functions?
What is method chaining and how do you implement it?
What is the call stack?
What is stack overflow in JavaScript?
What are the different ways to handle asynchronous operations?
How does the this keyword work in JavaScript?
What is the difference between async and defer on a script tag?
What is an IIFE and why would you use one?
What is the difference between an attribute and a property in the DOM?
How do you cancel a fetch request with AbortController?
What are getters and setters in JavaScript?
Why is extending built-in JavaScript objects not a good idea?
What are property flags and descriptors in JavaScript?
What is the difference between the load and DOMContentLoaded events?
What is functional programming in JavaScript?
What are tagged templates in JavaScript?
Explain the concept of currying in JavaScript
What is function composition?
What is the Observer pattern in JavaScript?
What is the Module pattern?
What is the Singleton pattern in JavaScript?
What is the Factory pattern?
What are iterators and iterables?
What are commonly used JavaScript design patterns?
What are generators in JavaScript?
What are dynamic imports in JavaScript?
What is the MutationObserver API?
What are Web Workers?
What are private class fields in JavaScript?
What is recursion and how do you optimize it?
Is JavaScript pass by value or pass by reference?
Why is 0.1 + 0.2 not equal to 0.3 in JavaScript?
What is the difference between Promise.race() and Promise.any()?
Why does setTimeout in a var loop log the same value every time?
What is a WeakMap and WeakSet?
What is the event loop in JavaScript?
What is the difference between microtasks and macrotasks?
What is a Proxy in JavaScript?
What is Reflect in JavaScript?
What is a service worker?
What is the execution context in JavaScript?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
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.
JavaScript cheatsheet
- Variables & types01
- Functions & scope02
- Objects & classes03
- Arrays, loops & syntax04
- Async & the event loop05
- Errors & strict mode06
- DOM & events07
- Browser APIs08
- Modules & builds09
- Performance & patterns10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 34 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in110 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.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.