JavaScript
JavaScript is the programming language of the web. Originally designed for browser interactivity, it has evolved into a versatile language running everywhere from servers (Node.js) to mobile apps to IoT devices.
Key Characteristics
- Dynamic typing: Variables can hold any type
- First-class functions: Functions are values
- Prototypal inheritance: Object-based, not class-based (though classes exist)
- Event-driven: Asynchronous by nature
- Single-threaded: One call stack (with async capabilities)
Modern JavaScript (ES6+)
// Arrow functions
const greet = (name) => `Hello, ${name}!`;
// Destructuring
const { name, age } = user;
const [first, ...rest] = items;
// Spread operator
const merged = { ...defaults, ...options };
// Async/await
const data = await fetchData();
// Optional chaining & nullish coalescing
const city = user?.address?.city ?? 'Unknown';
Runtime Environments
| Environment | Use Case |
|---|---|
| Browsers | Web applications, interactivity |
| Node.js | Servers, CLI tools, scripts |
| Deno | Secure Node alternative |
| Bun | Fast all-in-one toolkit |
| Electron | Desktop applications |
| React Native | Mobile applications |
What We Like
- Ubiquity: Runs everywhere, known by everyone
- Ecosystem: npm is the largest package registry
- Flexibility: Multiple paradigms (functional, OOP, procedural)
- Rapid iteration: Quick feedback loop in browsers
- Full-stack: Same language frontend and backend
What We Don't Like
- Can't think of any 😉
JavaScript vs TypeScript
For most projects, we recommend sticking with JavaScript because it's easier to understand for most developers and usually faster to work with. We'd use TypeScript if the codebase or application requires it - such as when working in a large team or for added safety in complex projects.
| Aspect | JavaScript | TypeScript |
|---|---|---|
| Types | Dynamic, runtime | Static, compile-time |
| Errors | Runtime | Caught in IDE |
| Tooling | Good | Excellent |
| Learning curve | Lower | Higher |
Best Practices
- Lint your code: ESLint with Airbnb or similar config
- Prefer const/let: Never use
var - Consider TypeScript: For any non-trivial project