Coding Manifestation Logo
Lesson 12

Functions

Functions help you write reusable code. They allow you to break down a problem into smaller, reusable blocks.

f(x){ }</>
  • What is a Function?
  • Function Declaration
  • Function Expression
  • Parameters & Arguments
  • Return Statement
  • Scope in Functions
  • Arrow Functions

A function is a block of code designed to perform a particular task. You can call (invoke) it whenever you need.

Reusable

Write once, use many times.

Organized

Break complex problems into smaller parts.

Maintainable

Easy to test and debug.

function add(a, b) {return a + b;}functionkeywordnameparametersbodyreturnstatement
JavaScript
Output
Your output will appear here...
  • // Declarationfunction name(param1, param2) {  // code  return value; // optional}
  • // Callname(arg1, arg2);

A function can return only one value. If you don’t return anything, it returns undefined.

  • Functions reduce code repetition.
  • Use parameters to make functions dynamic.
  • Use return to send a value back.
  • Functions create their own scope.
Input(Arguments)Function(Processing)Output(Return value)
PrevNext