Welcome to the JavaScript essentials guide! This document covers core concepts every developer should know. Let's dive in!
🐶 Variables & Data Types
JavaScript uses let
, const
, and var
for variable declaration.
let
allows reassignmentconst
is for constantsvar
is function-scoped (older style)
Common data types include:
- Primitive: Number, String, Boolean, Null, Undefined, Symbol, BigInt
- Object: Arrays, Dates, RegEx, etc.
💡 Tip: Always use const
unless you need to mutate the variable!
🧩 Functions
Functions are reusable blocks of code.
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("World")); // Output: Hello, World!
Arrow functions (ES6+):
const greet = (name) => `Hi, ${name}!`;
🎮 Control Structures
Use if/else
, switch
, for
, while
, and do/while
for logic flow.
Example:
for (let i = 0; i < 5; i++) {
console.log(i);
}
🏗️ Objects & Arrays
Objects store key-value pairs:
const person = { name: "Alice", age: 30 };
Arrays hold ordered collections:
const fruits = ["apple", "banana", "cherry"];
⚡ Asynchronous Programming
JavaScript handles async operations with:
async/await
Promise
objectssetTimeout
/setInterval
Async function example:
async function fetchData() {
const response = await fetch("https://api.example.com/data");
return response.json();
}
For deeper exploration, check our JavaScript Basics guide.