JavaScript essentials: 50 core concepts
Master the JavaScript every developer uses daily: scope, closures, equality, array methods, promises, async/await and the event loop.
Practice now
Study without an account
== vs ===Scheduled with the default Askesis timings. Progress is saved in this browser.
All 50 cards
- 1
==vs======compares without type coercion;==converts types firstjs0 == '' // true 0 === '' // false - 2
letvsconstBoth are block-scoped; aconstbinding can’t be reassignedObjects declared withconstcan still be mutated. - 3How is
varscoped?To the enclosing function, and it is hoisted (initialized asundefined) - 4Temporal dead zoneA
let/constvariable exists from the start of its block but throws a ReferenceError if used before its declaration - 5What is a closure?A function that keeps access to variables from the scope where it was createdjs
function counter() { let n = 0 return () => ++n } const next = counter() next() // 1 next() // 2 - 6What is
thisinside an arrow function?Arrows have no ownthis; they usethisfrom the enclosing scope - 7
typeof null'object', a long-standing quirk of the language - 8How do you check that a value is an array?
Array.isArray(value)typeof []is'object'. - 9The falsy values
false,0,-0,0n,'',null,undefined,NaN - 10
NaN === NaNfalse; useNumber.isNaN(x) - 11What does
a ?? breturn?bonly whenaisnullorundefined, otherwisea - 12
||vs??||falls back on any falsy value (like0or'');??only onnull/undefinedjs0 || 10 // 10 0 ?? 10 // 0 - 13Optional chaining
a?.breturnsundefinedinstead of throwing whenaisnullorundefinedjsuser?.address?.city callback?.() - 14Object destructuring with a defaultjs
const { name, age = 30 } = user - 15Swap two variablesjs
[a, b] = [b, a] - 16Concatenate arrays with spreadjs
const all = [...a, ...b] - 17Shallow-copy an object and override a keyjs
const next = { ...state, done: true } - 18Rest parametersCollect remaining arguments into an arrayjs
function sum(...nums) { return nums.reduce((a, b) => a + b, 0) } - 19Template literaljs
const msg = `Hi ${name}, you have ${count} cards` - 20What does
mapreturn?A new array with each element transformed by the callback - 21What does
filterreturn?A new array with the elements that pass the test - 22Sum an array with
reducejs[1, 2, 3].reduce((sum, x) => sum + x, 0) // 6 - 23
findvsfilterfindreturns the first match (orundefined);filterreturns every match in a new array - 24
somevseverysomeis true if any element passes;everyis true only if all pass - 25What does
forEachreturn?Alwaysundefined. You can’tbreakout of it; usefor...ofinstead - 26
for...ofvsfor...infor...ofiterates values of an iterable;for...initerates enumerable property keys - 27What is a Promise?An object for a value that will be available later: pending, then fulfilled or rejected
- 28What does an
asyncfunction return?Always a Promise;awaitinside it pauses until a promise settles - 29
Promise.allResolves with all results when every promise resolves; rejects on the first rejection - 30
Promise.allSettledWaits for every promise and never rejects; gives each one’s status and value or reason - 31
Promise.racevsPromise.anyracesettles like the first promise to settle;anyresolves with the first to fulfil - 32In what order does this log?js
setTimeout(() => console.log('timeout'), 0) Promise.resolve().then(() => console.log('micro')) console.log('sync')sync,micro,timeout: promise callbacks (microtasks) run before the next timer (macrotask) - 33Can you call a function declaration before it appears?Yes. Function declarations are hoisted with their body
- 34
thisin a plain function call in strict modeundefinedIn sloppy mode it is the global object. - 35
call,apply,bindcall(thisArg, ...args),apply(thisArg, argsArray);bindreturns a new function withthisfixed - 36What is the prototype chain?Objects inherit properties from their prototype, and its prototype, up to
null - 37Class syntaxSugar over prototypesjs
class Deck { constructor(name) { this.name = name } rename(n) { this.name = n } } - 38Private class fieldDeclared with
#; only accessible inside the class bodyjsclass Counter { #n = 0 inc() { return ++this.#n } } - 39Deep-copy an object
structuredClone(obj)Spread ({ ...obj }) only copies one level. - 40Convert between objects and JSON
JSON.stringify(obj)andJSON.parse(text) - 41
Mapvs plain objectA Map accepts keys of any type, keeps insertion order and has.size - 42Remove duplicates from an arrayjs
const unique = [...new Set(items)] - 43WeakMapA map whose keys are objects held weakly, so they can still be garbage-collected
- 44SymbolA unique, immutable primitive, often used as a non-colliding property key
- 45Named vs default exportjs
export function load() {} // import { load } from './x.js' export default function () {} // import anything from './x.js' - 46When is strict mode on automatically?Inside ES modules and class bodiesElsewhere, enable it with
"use strict". - 47DebounceDelay a function until calls have stopped for a whilejs
function debounce(fn, ms) { let timer return (...args) => { clearTimeout(timer) timer = setTimeout(() => fn(...args), ms) } } - 48
includesvsindexOfincludesreturns a boolean and findsNaN;indexOfreturns a position and can’t findNaN - 49
parseInt('42px', 10)42; it reads digits until the first non-digitNumber('42px')isNaN. - 50
Array.from({ length: 3 }, (_, i) => i)[0, 1, 2]
Frequently asked questions
Is this deck good for interview prep?
Yes. It covers the questions that come up most: closures, this, equality, promises and the event loop.
Do I need to know another language first?
No, but it assumes you have written a little JavaScript and know what variables, functions and arrays are.
Does it cover TypeScript?
Not yet. Everything here applies to TypeScript too, since TypeScript compiles to JavaScript.
More in Programming
Advanced JS
Fifty advanced JavaScript cards: event-loop ordering puzzles, generators and async iteration, this binding, Proxy and Reflect, modules, AbortController and coercion edge cases.
50 cardsTypeScript
Learn the TypeScript you use every day: narrowing, generics, keyof, mapped and conditional types, utility types, satisfies and strict mode, with code on every card.
50 cardsPython
Learn idiomatic Python fast: comprehensions, f-strings, args and kwargs, generators, decorators, context managers and the standard library.
50 cardsGit & terminal
The Git commands and shell skills developers use every day: branching, rebasing, undoing mistakes, pipes, redirects, permissions and processes.
50 cardsJava
Core Java with short snippets: equals vs ==, records, sealed types, collections, generics, exceptions, streams, lambdas and JVM basics.
50 cardsC#
C# and .NET fundamentals with short snippets: value vs reference types, properties, records, nullable reference types, LINQ, async/await and DI.
50 cardsKotlin
Kotlin fundamentals with short snippets: null safety, val vs var, data and sealed classes, extension functions, scope functions and coroutines.
50 cardsSwift
Swift fundamentals with short snippets: optionals, structs vs classes, protocols, enums with associated values, closures, ARC, async/await and SwiftUI.
50 cardsFlutter
Flutter and Dart basics: null safety, futures and streams, stateless vs stateful widgets, setState, hot reload, keys, layout and state management.
50 cardsPHP
Modern PHP 8 with short snippets: strict types, arrays, match, nullsafe and named arguments, enums, readonly, Composer, PDO and password_hash.
50 cardsRuby
Ruby fundamentals with short snippets: blocks, procs and lambdas, symbols, Enumerable, mixins, truthiness, method_missing, gems and Bundler.
50 cardsGo
Go (Golang) fundamentals with short, idiomatic snippets: slices vs arrays, maps, defer, error wrapping, interfaces, goroutines, channels, select and context.
50 cardsRust
Learn the Rust that the compiler keeps asking about: ownership, borrowing, lifetimes, Option and Result, traits, closures, smart pointers and async.
50 cardsC++
Modern C++ in short snippets: references vs pointers, RAII, smart pointers, move semantics, STL containers and algorithms, const, templates and UB.
50 cardsHaskell
Haskell fundamentals with short code: types and type classes, pattern matching, laziness, Maybe and Either, folds, Functor, Applicative and Monad.
50 cardsElixir
Elixir fundamentals with short snippets: immutability, pattern matching, the pipe operator, Enum vs Stream, processes, GenServer, supervisors and mix.
50 cardsx86-64 assembly
x86-64 assembly in Intel syntax: registers and sub-registers, flags, mov and lea, jumps, the stack frame, the System V calling convention and Linux syscalls.
50 cardsRegex
Learn regular expressions for good: anchors, classes, greedy vs lazy quantifiers, groups, lookarounds, flags, replacements and the backtracking trap.
50 cards