Skip to main content

JavaScript Function Literals

A Function Literal is an expression that defines an unnamed function. So why it is called Functional Literals?

Because it has an unnamed function within a variable just along with its parameters. So, we call this unnamed function the function literal.


It is much alike to how a normal function statement is written but instead of a function name, it is confined within a variable that is defined.

var varName = function(parameters)
    //body of the function


var number = function(x, y)
    return x + y;

var sum = number(50, 50)

Output: 100

So as we can see here, I have created a function literal passing the parameters as x and y but it has no name like a normal function, that's the goal of it. So we can simply then access the function with the expression we declared called the number and pass in the arguments for the parameters.

Submitted by arilio666 on October 27, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.