Functions in javascript

Published: (December 14, 2025 at 08:56 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

What is a Function?

A function is a block of code designed to perform a specific task.
It runs only when it is called.

function add() {
  console.log("Hello, World!");
}

add();

Function Expression

A function can also be stored in a variable.

const multiply = function(a, b) {
  return a * b;
};

console.log(multiply(4, 2));

Arrow Functions

Arrow functions provide a shorter syntax.

const subtract = (a, b) => a - b;

console.log(subtract(10, 4));
Back to Blog

Related posts

Read more »

JSDoc is TypeScript

In May 2023 an internal refactoring PRhttps://github.com/sveltejs/svelte/pull/8569 from the Svelte repo made it to the front page of Hacker News. The superficia...

Preferred Web Tech Stacks in Australia

Why Tech Stack Selection Matters in Australia Australian businesses prioritize quality, security, and performance. Websites are expected to work seamlessly acr...