How to Create a Noop Function in JavaScript?

A "noop" (no-op, or NOP) is a "no-operation" function, which does nothing. You can create a noop function in JavaScript using either, a function declaration or a function expression, like so:

// function declaration/statement
function noop() {}
// function expression
const noop = function () {};

The same code can be written in a shorter syntax using the arrow function (introduced in ES6), for example, like so:

// ES6+
// function expression
const noop = () => {};

This post was published (and was last revised ) by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.