Logo

dev-resources.site

for different kinds of informations.

Javascript Functions Quick References

Published at
12/21/2023
Categories
javascript
cheatsheet
Author
Lam
Categories
2 categories in total
javascript
open
cheatsheet
open
Javascript Functions Quick References

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

Featured ones: