Javascript Functions Quick References
Lam
Posted on December 21, 2023
JavaScript Functions Cheat Sheet
Function Declaration
Syntax
function functionName(parameters) {
// Function body
return result;
}
Example
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet('World'));
Function Expression
Syntax
const functionName = function(parameters) {
// Function body
return result;
};
Example
const greet = function(name) {
return `Hello, ${name}!`;
};
console.log(greet('World'));
Arrow Function
Syntax
const functionName = (parameters) => {
// Function body
return result;
};
Example
const greet = (name) => `Hello, ${name}!`;
console.log(greet('World'));
Immediately Invoked Function Expression (IIFE)
Syntax
(function() {
// Function body
})();
Example
(function() {
console.log('IIFE executed');
})();
Function Parameters and Arguments
Example
function addNumbers(a, b) {
return a + b;
}
console.log(addNumbers(5, 10)); // Output: 15
More: Javascript Cheat Sheet
💖 💪 🙅 🚩
Lam
Posted on December 21, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.