What is the inline function in JavaScript ?

16 Jun, 2022
In JavaScript, inline function is a special type of anonymous function which is assigned to a variable, or in other words, an anonymous function with a name. JavaScript does not support the traditional concept of inline function like in C or C++. Thus anonymous function and inline function is practically the same. Unlike normal function, they are created at runtime.
Syntax:
Function:
function func() {
    //Your Code Here
}
Anonymous function:
function() {
    //Your Code Here
}
Inline function
var func = function() { 
    //Your Code Here 
};
Explanation:
Making an inline function is really simple. First, make an anonymous function(a function with no name), and then assign it to a variable.
Example: 
html
<!DOCTYPE html><html lang="en"> <head>    <meta charset="UTF-8">    <meta name="viewport"          content="width=device-width,                   initial-scale=1.0">    <meta http-equiv="X-UA-Compatible"          content="ie=edge">       <title>JS Functions</title>    <!-- jQuery CDN -->    <script src="https://code.jquery.com/jquery-3.4.1.min.js"            integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="            crossorigin="anonymous">    </script>       <!-- End of CDN -->    <style>        button {            background-color: #4CAF50;            border: none;            color: white;            padding: 15px 32px;            text-align: center;            font-size: 16px;            margin: 8px 2px;            cursor: pointer;            display: block;            width: 270px;        }    </style></head> <body>     <h1 style="text-align:center;color:green;">GeeksforGeeks</h1>    <p align="center">        <button id="function">function</button>        <button id="anonymous-function">anonymous function</button>        <button id="inline-function">inline function</button>    </p>    <script type="text/javascript">        //function        function func() {            alert("Hello I'm inside function");        }        $('#function').click(func);         //anonymous function        $('#anonymous-function').click(function() {            alert("Hello I'm inside anonymous function");        });         //inline function        var inline_func = function() {            alert("Hello I'm inside inline function");        };        $('#inline-function').click(inline_func);    </script></body> </html>
Output: 
Clicking on any of the above button will call the respective function and an alert message will show up. Let’s say “inline function” button is clicked then the following alert message will pop up.
simmytarika5
Picked
JavaScript
Technical Scripter
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
Roadmap to Learn JavaScript For Beginners
Difference Between PUT and PATCH Request
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?