JavaScript Tutorial
Functions and Control Flow
Write functions, arrow functions, conditions and loops.
Concept
Functions are first-class values in JavaScript, so they can be stored, passed and returned. Arrow functions are concise but have different this behavior than traditional function declarations.
Control flow uses if, switch and loops. Array iteration helpers such as map, filter and forEach are often clearer for collection transformations.
Example
const square = (n) => n * n;
for (let i = 1; i <= 4; i += 1) {
console.log(square(i));
}
Type the example yourself and change at least one value. Small experiments reveal syntax and behavior faster than passive reading.
Practice Tasks
- Write a function that returns the larger of two numbers.
- Use filter to keep even numbers from an array.
- Use map to create an array of squares.
Key Takeaways
- Functions are reusable values.
- Arrow functions are useful but not identical to function declarations.
- Choose loops or array methods based on clarity.
Previous
← Variables, Types and Operators
← Variables, Types and Operators
Next
Arrays and Objects →
Arrays and Objects →