Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

What is the inline function in JavaScript ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.


  • Function:
function func() {
    //Your Code Here
  • Anonymous function:
function() {
    //Your Code Here
  • Inline function
var func = function() { 
    //Your Code Here 


Making an inline function is really simple. First, make an anonymous function(a function with no name), and then assign it to a variable.



<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
    <meta http-equiv="X-UA-Compatible"
    <title>JS Functions</title>
    <!-- jQuery CDN -->
    <!-- End of CDN -->
        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;
    <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>
    <script type="text/javascript">
        function func() {
            alert("Hello I'm inside function");
        //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");

Output: 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.


My Personal Notes arrow_drop_up
Last Updated : 16 Jun, 2022
Like Article
Save Article
Similar Reads
Related Tutorials