javascript
Copy code
function functionName(parameters) {
// code to be executed
}
javascript
Copy code
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("Alice")); // Output: Hello, Alice!
javascript
Copy code
const functionName = function(parameters) {
// code to be executed
};
javascript
Copy code
const square = function(x) {
return x * x;
};
console.log(square(4)); // Output: 16
this
context.javascript
Copy code
const functionName = (parameters) => {
// code to be executed
};
javascript
Copy code
const add = (a, b) => a + b;
console.log(add(3, 5)); // Output: 8
javascript
Copy code
(function() {
// code to be executed
})();
javascript
Copy code
(function() {
const message = "This is an IIFE!";
console.log(message);
})(); // Output: This is an IIFE!
javascript
Copy code
function fetchData(callback) {
setTimeout(() => {
const data = "Data received!";
callback(data);
}, 1000);
}
fetchData((data) => {
console.log(data); // Output: Data received!
});
javascript
Copy code
function applyOperation(a, b, operation) {
return operation(a, b);
}
const multiply = (x, y) => x * y;
console.log(applyOperation(4, 5, multiply)); // Output: 20
javascript
Copy code
function functionName(...parameters) {
// code to be executed
}
javascript
Copy code
function sum(...numbers) {
return numbers.reduce((acc, num) => acc + num, 0);
}
console.log(sum(1, 2, 3, 4)); // Output: 10
undefined
is passed.javascript
Copy code
function functionName(parameter = defaultValue) {
// code to be executed
}
javascript
Copy code
function greet(name = "Guest") {
return Hello, ${name}!;
}
console.log(greet()); // Output: Hello, Guest!
© 2025 Invastor. All Rights Reserved
User Comments