Skip to main content
D
JavaScript
JavaScript Functions

JavaScript Functions

JavaScript functions bundle reusable blocks of code.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript functions store instructions that you want to use multiple times. Instead of copying and pasting the same ten lines of code, developers wrap them inside a function and call its name whenever needed.

Syntax

Syntax
1/* function syntax */
2function myFunc(param) {
3  // Code runs here
4}

Example

Example
1/* this creates a function */
2function multiply(a, b) {
3  return a * b;
4}
5
6let result = multiply(4, 3);

Key Points

  • The `function` keyword creates the block.
  • Parentheses hold incoming variables called parameters.
  • Curly braces contain the actual code to execute.
  • The `return` keyword sends data back.

Up Next

Continue your journey with the next topic.

Go to JS Objects