General Programming Concepts
Study Notes
Declaration — Tells the compiler/interpreter that a variable (or function) exists and its type (if applicable).
int x; // declaration
Initialization — Gives the variable its first value (often at declaration).
int x = 10; // declaration + initialization
Assignment — Updates the value after declaration (and possibly after initialization).
int x; // declaration
x = 10; // initialization (first assignment)
x = 20; // reassignment
- Node.js is a single-threaded, non-blocking, asynchronous runtime.
- Linux treats threads as lightweight processes; Windows treats threads as threads.
Async / Await
- async makes a function return a Promise.
- await pauses inside an async function until the Promise settles.
- Lets you write asynchronous code in a synchronous style.
- Everything after an
awaitis scheduled on the event loop.
async function fetchData() {
const res = await fetch('/api');
return await res.json();
}
With multi-process programming you can run code on different cores or machines (e.g., brute-force tasks) to parallelize work.
JavaScript’s ToBoolean converts any expression into a boolean. while(expr) runs only when ToBoolean(expr) === true.
CORS — Cross-Origin Resource Sharing controls how resources are requested from different origins.
Process
An instance of a program with its own address space, resources, and execution state.
Thread
A smaller execution unit within a process that shares the same memory with other threads in the process.
Process — An independent program in execution.
Key Points
- Has its own memory (RAM space).
- Own CPU time, stack, heap, file handles.
- Crashing one process doesn't affect others.
- Examples: Chrome.exe, VSCode.exe, python.exe
What is a Thread? The smallest unit of execution inside a process.
Key Points
- Threads share the memory of the process.
- Lightweight compared to a process.
- One process can have multiple threads.
- Examples: A browser tab, file download thread, render thread.
Event listeners subscribe to events and are invoked whenever the event occurs while the listener is active. You can attach listeners to specific DOM elements as needed.
Namespaces organize code and prevent naming conflicts by grouping related classes and components under a logical container. Supported across many languages (C#, C++, Java packages, Python modules, PHP, TypeScript, Go, Rust).