JavaScript Basics - Study Guide
Core JavaScript concepts and fundamentals in a spaced repetition format
Cards
===
(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)
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.
- Call Stack - Where synchronous code executes
- Callback Queue - Where callbacks wait to be processed
- Microtask Queue - Higher priority queue (for Promises)
- 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.
- Callbacks:
fetchData(function(error, data) { if (error) handleError(error); else processData(data); });
- Promises:
fetchData() .then(data => processData(data)) .catch(error => handleError(error));
- 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.
If you find this study guide helpful, consider buying me a coffee