Difference between function expression vs declaration in JavaScript Last Updated : 22 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Function Declaration: A Function Declaration( or a Function Statement) defines a function with the specified parameters without requiring a variable assignment. They exist on their own, i.e, they are standalone constructs and cannot be nested within a non-function block. A function is declared using the function keyword. Syntax:function gfg(parameter1, parameter2) { //A set of statements } Function Expression: A Function Expression works just like a function declaration or a function statement, the only difference is that a function name is NOT started in a function expression, that is, anonymous functions are created in function expressions. The function expressions run as soon as they are defined. Syntax:var gfg = function(parameter1, parameter2) { //A set of statements } Example 1: Using a Function Declaration javascript <!DOCTYPE html> <html> <head> <title>Function Declaration</title> </head> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <h3>Function Declaration</h3> <script> function gfg(a, b) { return a * b; } var result = gfg(5, 5); document.write(result); </script> </center> </body> </html> Output: 25 Example 2: Using a Function Expression javascript <!DOCTYPE html> <html> <head> <title>Function Expression</title> </head> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <h3>Function Expression</h3> <script> var gfg = function(a, b) { return a * b; } document.write(gfg(5, 5)); </script> </center> </body> </html> Output: 25 Comment More infoAdvertise with us Next Article Difference between function expression vs declaration in JavaScript N Nilarjun Follow Improve Article Tags : Difference Between JavaScript Web Technologies Web Technologies - Difference Between Similar Reads Difference between âfunction declarationâ and âfunction expression' in JavaScript Functions in JavaScript allow us to carry out some set of actions, important decisions, or calculations and even make our website more interactive. In this article, we will learn the difference between âfunction declarationâ and âfunction expressionâ. The similarity is both use the keyword function 2 min read Difference Between Default & Named Exports in JavaScript In JavaScript, exports allow you to share code between modules. There are two main types: default exports and named exports.Used to export functions, objects, or variables.Default exports allow importing with any name.Named exports require importing by the exact name.Named ExportsNamed exports let u 4 min read Difference between Methods and Functions in JavaScript Grasping the difference between methods and functions in JavaScript is essential for developers at all levels. While both are fundamental to writing effective code, they serve different purposes and are used in various contexts. This article breaks down the key distinctions between methods and funct 3 min read Difference between First-Class and Higher-Order Functions in JavaScript Understanding the difference between first-class and higher-order functions in JavaScript is important. These are big concepts in programming, especially in the kind of coding used for making websites. This article is all about explaining what they are, how they are used, and why they are so importa 3 min read Explain the Different Function States in JavaScript In JavaScript, we can create functions in many different ways according to the need for the specific operation. For example, sometimes we need asynchronous functions or synchronous functions. Â In this article, we will discuss the difference between the function Person( ) { }, let person = Person ( ) 3 min read Difference between AngularJS Expressions and JavaScript Expressions In this article, we will see what are AngularJS Expressions & JavaScript expressions, along with understanding their basic implementation through the illustrations & understand the differences between them. Angularjs Expression: Expressions in AngularJS are used to bind application data to H 3 min read Difference between Anonymous and Named functions in JavaScript In JavaScript or in any programming language per say, functions, loops, mathematical operators and variables are the most widely used tools. This article will tell you about the difference between anonymous functions and named functions. We will discuss all the required concepts in this article to k 4 min read Difference Between Function Overloading and Function Overriding in JavaScript Function overloading and function overriding are two important concepts in object-oriented programming (OOP). Function overloading allows the creation of multiple functions with the same name but different parameters. Function overriding allows the subclass or child class to provide the specific imp 3 min read Using the function* Declaration in JavaScript The function* declaration is used to define a generator that returns a Generator object. Generators are very powerful for asynchronous programming as they aim to resolve callback problems. In a generator, the yield keyword is used instead of return. The yield statement suspends the functionâs execut 2 min read Difference Between Scope and Closures in JavaScript The scope and closures are fundamental concepts that play a crucial role in how variables are accessed and managed within the functions and blocks of code. In this article, we will learn about the difference between scope and closures in JavaScript. What is Scope?The Scope in JavaScript refers to th 2 min read Like