for(let i = 0; i < 10; i++) { function }
The for loop is used to iterate over a block of code a number of times.
for (const item of object) { console.log(` ${item} : ${object[item]} `); }
The for-of loop is used to iterate over iterable objects like arrays, strings, maps, sets, etc. It provides a simpler syntax compared to the traditional for loop when working with iterables.
The Example prints all attributes of the object with their values.
for (const key in object) { function }
The for-in loop is used to iterate over the enumerable properties of an object. It allows you to access the keys of an object, but not the values directly.
while (condition) { function }
do { function } while (condition);
The while loop executes a block of code as long as a specified condition is true.
The do-while loop is similar, but it guarantees that the block of code will be executed at least once.
array.forEach((item) => { function });
array.forEach((item, index) => { function });
array.forEach((item, index, array) => { function });
The forEach method is an array method that executes a provided function once for each array element. It is often used to perform side effects on each element of the array, such as logging or modifying the elements.
Note: The forEach cannot be stopped by return or break like a traditional for loop.
for (const item of array) { function }
for (const key in object) { function }
do { function } while (condition);
Augments and parameters are the components that make up the structure of a function.
Overloaded functions are functions that can take a variable number of arguments, allowing for more flexible and dynamic code.
array.forEach((item) => { function });array.forEach((item, index) => { function });array.forEach((item, index, array) => { function });function example(a) { ... }function example(a, b) { ... }function example(a, b, c) { ... }function example() { return value; }
The return statement is used to exit a function and return a value to the caller. It can be used to stop the execution of a function and provide a result back to the code that called the function.
break;
continue;
The break statement is used to exit a loop or switch statement prematurely, while the continue statement is used to skip the current iteration of a loop and move on to the next one.
for (let i = 0; i < 5; i++) { for (let j = 0; j < 5; j++) { console.log(`i: ${i}, j: ${j}`); } }
Nested loops are loops that are contained within another loop.
const example = (parameters) => { function }
Arrow functions are a more concise syntax for writing function expressions in JavaScript. They are often used for short, simple functions and can help improve readability.
Arrow functions do not have their own `this` context, which makes them useful for preserving the context of `this` in callbacks and event handlers.
function (parameters) { function }
Anonymous functions are functions that do not have a name.
function example(callback) { callback(); }
Callback functions are functions that are passed as arguments to other functions and are executed after a certain event or condition is met.
They are commonly used for asynchronous operations, such as handling user input, making API calls, or performing tasks after a delay.
const Colors = { RED: 'red', GREEN: 'green', BLUE: 'blue' };
An enum (short for "enumeration") is a data structure that allows you to define a set of named constants. In JavaScript, you can create an enum using an object, where the keys represent the names of the constants and the values represent their corresponding values.