DEV Community

Khadija Batool Gardezi
Khadija Batool Gardezi

Posted on

Callback function in js?🧐

So basically, a callback function is a function() passed as an argument to another function. It is executed for each element in the array during iteration.

Example:
recipe => recipe.name.toLowerCase().includes(filter.toLowerCase())

Method: .filter()
Loops through each item in the recipes array and runs the callback function to decide if that item should be included in the filtered results.

Callback Function:
recipe => recipe.name.toLowerCase().includes(filter.toLowerCase())
Parameters:
recipe: Represents the current element in the recipe array.

recipe.name.toLowerCase(): Converts the recipe's name to lowercase for case-insensitive comparison.

.includes(filter.toLowerCase()): Checks if the lowercase filter string is part of the recipe's name.

The arrow function (recipe => recipe.name...) is the callback here.

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay