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
Top comments (0)