Control Structures and Functions in JavaScript
🔁 Control Structures & 🧩 Functions in JavaScript
Control structures enable decision-making and repetition, fundamental for dynamic programming.
🧭 Conditional Statements
if
,else
,switch
if (age >= 18) {
console.log('Adult');
} else {
console.log('Minor');
}
🔄 Loops: for
, while
, do...while
for (let i = 0; i < 5; i++) {
console.log(i);
}
🛠️ Functions are reusable blocks of code:
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet('Bob')); // Output: Hello, Bob!
🧠 Control flow and functions form the backbone of programming logic, enabling complex behavior with concise code.