Skip to main content
Oscar Campos

JavaScript Basics - Study Guide

Core JavaScript concepts and fundamentals in a spaced repetition format

Cards

What are JavaScript's primitive data types?
JavaScript has 7 primitive data types: - String - Number - Boolean - null - undefined - Symbol (added in ES6) - BigInt (added in ES2020)
1/5
What's the difference between `==` and `===` in JavaScript?
`==` (equality operator) compares values after converting them to a common type

=== (strict equality operator) compares both values AND types without conversion

Example:

5 == "5" // true (string "5" is converted to number 5) 5 === "5" // false (different types: number vs string)

Explain the concept of JavaScript closure.
A closure is a function that remembers its outer variables and can access them. In JavaScript, all functions are closures.

Closures allow functions to maintain access to variables from their parent scope even after the parent function has finished executing.

Example: javascript function createCounter() { let count = 0; return function() { return ++count; }; }

const counter = createCounter(); counter(); // 1 counter(); // 2 counter(); // 3

In this example, the inner function maintains access to count even after createCounter() has finished executing.

What is the event loop in JavaScript?
The event loop is JavaScript's mechanism for handling asynchronous operations. It consists of:
  1. Call Stack - Where synchronous code executes
  2. Callback Queue - Where callbacks wait to be processed
  3. Microtask Queue - Higher priority queue (for Promises)
  4. Event Loop - Continuously checks if the call stack is empty, then moves callbacks to the stack

This allows JavaScript to be non-blocking despite being single-threaded.

How do you handle asynchronous operations in JavaScript?
Three main approaches to handle asynchronous operations:
  1. Callbacks:

fetchData(function(error, data) { if (error) handleError(error); else processData(data); });

  1. Promises:

fetchData() .then(data => processData(data)) .catch(error => handleError(error));

  1. Async/Await (ES2017):

async function getData() { try { const data = await fetchData(); processData(data); } catch (error) { handleError(error); } }

Async/await is built on promises and provides the most readable syntax.

Cards: 5 Due today: 5

If you find this study guide helpful, consider buying me a coffee