---
title: What Are Callback Functions in JavaScript Programming?
description: Understand callback functions in JavaScript, their role in event handling, and how to use them with named and anonymous functions through a practical example.
image: https://blog.rheinwerk-computing.com/hubfs/What%20Are%20Callback%20Functions%20in%20JavaScript%20Programming_.png
---

[![Rheinwerk Computing Logo](https://blog.rheinwerk-computing.com/hubfs/computing_logo-header.svg)](https://blog.rheinwerk-computing.com/) [Blog](https://blog.rheinwerk-computing.com)

- Books 
    - Get an overview of our wide selection of books on every relevant computing topic. 
          - [General Computing](https://www.sap-press.com/rheinwerk-computing/general-computing/)
          - [DevOps](https://www.sap-press.com/rheinwerk-computing/devops/)
          - [Programming Languages](https://www.sap-press.com/rheinwerk-computing/programming-languages/)
          - [Security](https://www.sap-press.com/rheinwerk-computing/security/)
          - [Software Development](https://www.sap-press.com/rheinwerk-computing/software-development/)
- Book Subscription 
    - Get unlimited access to all Rheinwerk Computing books! 
          - [Programming Subscription](https://sap-press.com/subscriptions/)

[Programming Languages](https://blog.rheinwerk-computing.com/tag/programming-languages)

# What Are Callback Functions in JavaScript Programming?

![Rheinwerk Computing](https://blog.rheinwerk-computing.com/hubfs/RW-logo-300x300.png)  by [Rheinwerk Computing](https://blog.rheinwerk-computing.com/author/rheinwerk-computing)

The reference to a function in JavaScript can be transferred to another function for internal use.

 

In this context, the transferred function is referred to as the *callback function*. You can transfer both named functions and anonymous functions as callback functions. Callback functions are also used to handle events in [JavaScript programming](https://learning.rheinwerk-computing.com/javascript).

 

In the following program, the output() function is called twice. It’s used to output a regular sequence of values. A mathematical calculation is then carried out for each of these values, the result of which is displayed next to the value.

 

The mathematical calculation can be freely selected. It’s defined in a function, and a reference to this function is transferred to the output() function when it’s called:

- The first call passes a reference to the named function square(), which returns the square of the transferred value.
- The second call transfers an anonymous function that returns the reciprocal of the transferred value.

Here’s the program:

 

`... <head> ...`

`   <script>`

`      function square(x)`

`      {`

`         return x * x;`

`      }`

 

`      function output(from, to, step, fct)`

`      {`

`         for(let p = from; p < to + step / 2.0; p += step)`

`            document.write(p + " " + fct(p) + "<br>");`

`         document.write("<br>");`

`      }`

`   </script>`

`</head>`

`<body><p>`

`   <script>`

`      output(5.0, 15.0, 2.5, square);`

`      output(3.0, 7.0, 1.0, function(p) { return 1 / p; });`

`   </script></p>`

`</body></html>`

 

The first call calculates the squares of the numbers from 5 to 15 in steps of 2.5, and the second call calculates the reciprocal values of the numbers from 3 to 7 in steps of 1.

 

The output of the program is shown in this figure:

 

![Callback Function](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Feb-05-2025-04-28-44-5328-PM.png?width=867&height=741&name=image-png-Feb-05-2025-04-28-44-5328-PM.png)

 

Editor’s note: This post has been adapted from a section of the book *[Getting Started with JavaScript](https://www.sap-press.com/getting-started-with-javascript_5875/?utm_source=sappressblog&utm_medium=referral&utm_campaign=Blogs&utm_term=2583_chapter2&utm_content=2583)* by Thomas Theis.

## Recommendation

[![Getting Started with JavaScript](https://blog.rheinwerk-computing.com/hs-fs/hubfs/social-suggested-images/2583_2d-Nov-18-2024-03-43-35-2581-PM-1.png?width=170&name=2583_2d-Nov-18-2024-03-43-35-2581-PM-1.png)](https://www.sap-press.com/getting-started-with-javascript_5875/?utm_source=sappressblog&utm_medium=referral&utm_campaign=Blogs&utm_term=2583_chapter2&utm_content=2583)

**Getting Started with JavaScript**

New to programming and JavaScript? Look no further! With this beginner’s guide, learn the language ABCs and start developing applications. Walk through the programming basics: branches, functions, methods, objects, and more. Then create forms and events; use the Document Object Model (DOM); and work with large data sets, processing strings, mathematics, time, and other data structures. Design your web and mobile applications using tools like Ajax, CSS, jQuery, and Onsen UI. Follow code examples and expert tips, and you’ll be developing in no time!

[Learn More](https://www.sap-press.com/getting-started-with-javascript_5875/?utm_source=sappressblog&utm_medium=referral&utm_campaign=Blogs&utm_term=2583_chapter2&utm_content=2583)

![Rheinwerk Computing](https://blog.rheinwerk-computing.com/hubfs/RW-logo-300x300.png)

**by [Rheinwerk Computing](https://blog.rheinwerk-computing.com/author/rheinwerk-computing)**

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes books by leading experts in the fields of programming, administration, security, analytics, and more.

[Programming Languages](https://blog.rheinwerk-computing.com/tag/programming-languages) [JavaScript](https://blog.rheinwerk-computing.com/tag/javascript)

[![Share on facebook](https://7528309.fs1.hubspotusercontent-na1.net/hub/7528309/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/facebook-color.png?width=24&name=facebook-color.png)](https://www.facebook.com/share.php?u=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-callback-functions-in-javascript-programming%3Futm_medium%3Dsocial%26utm_source%3Dfacebook) [![Share on linkedin](https://7528302.fs1.hubspotusercontent-na1.net/hub/7528302/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/linkedin-color.png?width=24&name=linkedin-color.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-callback-functions-in-javascript-programming%3Futm_medium%3Dsocial%26utm_source%3Dlinkedin) [![Share on twitter](https://7528304.fs1.hubspotusercontent-na1.net/hub/7528304/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/twitter-color.png?width=24&name=twitter-color.png)](https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-callback-functions-in-javascript-programming%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&url=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-callback-functions-in-javascript-programming%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&source=tweetbutton&text=) [![Share on email](https://7528311.fs1.hubspotusercontent-na1.net/hub/7528311/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/email-color.png?width=24&name=email-color.png)](mailto:?subject=Check+out+https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-callback-functions-in-javascript-programming%3Futm_medium%3Dsocial%26utm_source%3Demail&body=Check+out+https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-callback-functions-in-javascript-programming%3Futm_medium%3Dsocial%26utm_source%3Demail)

### Comments

### Latest Blog Posts

[![Mastering JavaScript Promises: A Guide to Asynchronous Programming](https://blog.rheinwerk-computing.com/hs-fs/hubfs/Mastering%20JavaScript%20Promises_%20A%20Guide%20to%20Asynchronous%20Programming.png?height=600&name=Mastering%20JavaScript%20Promises_%20A%20Guide%20to%20Asynchronous%20Programming.png)](https://blog.rheinwerk-computing.com/mastering-javascript-promises-a-guide-to-asynchronous-programming)

[JavaScript](https://blog.rheinwerk-computing.com/tag/javascript)

## [Mastering JavaScript Promises: A Guide to Asynchronous Programming](https://blog.rheinwerk-computing.com/mastering-javascript-promises-a-guide-to-asynchronous-programming)

[Read More](https://blog.rheinwerk-computing.com/mastering-javascript-promises-a-guide-to-asynchronous-programming)

[![Mathematical Functions in Python](https://blog.rheinwerk-computing.com/hs-fs/hubfs/Mathematical%20Functions%20in%20Python.png?height=600&name=Mathematical%20Functions%20in%20Python.png)](https://blog.rheinwerk-computing.com/mathematical-functions-in-python)

[Python](https://blog.rheinwerk-computing.com/tag/python)

## [Mathematical Functions in Python](https://blog.rheinwerk-computing.com/mathematical-functions-in-python)

[Read More](https://blog.rheinwerk-computing.com/mathematical-functions-in-python)

**Subscribe to our blog!**Get notified about future blog updates.

- <https://www.linkedin.com/showcase/rheinwerk-computing/>
- <https://www.youtube.com/channel/UChj-U-uWGM7qRlHXSFU93ew>
- <https://blog.rheinwerk-computing.com/rss.xml>

### The official Rheinwerk Computing Blog

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes resources that will help you accelerate your computing journey. The Rheinwerk Computing Blog is designed to provide helpful, actionable information on a variety of topics, including programming, administration, security, and analytics!

### Blog Topics

- [All Topics](https://blog.rheinwerk-computing.com)
- [Programming Languages](https://blog.rheinwerk-computing.com/tag/programming-languages)
- [How To](https://blog.rheinwerk-computing.com/tag/how-to)
- [JavaScript](https://blog.rheinwerk-computing.com/tag/javascript)
- [DevOps](https://blog.rheinwerk-computing.com/tag/devops)
- [Web Development](https://blog.rheinwerk-computing.com/tag/web-development)
- [Python](https://blog.rheinwerk-computing.com/tag/python)
- [What Is?](https://blog.rheinwerk-computing.com/tag/what-is)
- [Cybersecurity](https://blog.rheinwerk-computing.com/tag/cybersecurity)
- [Software Development](https://blog.rheinwerk-computing.com/tag/software-development)
- [Java](https://blog.rheinwerk-computing.com/tag/java)

### Blog curated by

[![Rheinwerk Computing Logo](https://blog.rheinwerk-computing.com/hubfs/computing_logo-header.svg)](https://www.sap-press.com/rheinwerk-computing/) [Visit Rheinwerk Computing Store](https://www.sap-press.com/rheinwerk-computing/)

### About

- [Home](https://sap-press.com/)
- [About Us](https://sap-press.com/the-publisher/)
- [Contact](mailto:info@rheinwerk-publishing.com)
- [Legal Notes](https://sap-press.com/legal-notes/)
- [Privacy Policy](https://sap-press.com/privacy/)
- [Terms of Use](https://sap-press.com/terms/)

© 2026 Rheinwerk Publishing, Inc. | Change Privacy Options

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Rheinwerk Computing",
    "url" : "https://blog.rheinwerk-computing.com/author/rheinwerk-computing"
  },
  "dateModified" : "2025-12-17T14:02:55.420Z",
  "datePublished" : "2025-02-12T14:00:00.000Z",
  "headline" : "What Are Callback Functions in JavaScript Programming?",
  "image" : [ "https://blog.rheinwerk-computing.com/hubfs/What%20Are%20Callback%20Functions%20in%20JavaScript%20Programming_.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.rheinwerk-computing.com/what-are-callback-functions-in-javascript-programming",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.rheinwerk-computing.com/hubfs/Logo-1.jpg"
    },
    "name" : "Rheinwerk Publishing, Inc."
  }
}
```