Difference between ‘function declaration’ and ‘function expression' in JavaScript Last Updated : 03 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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 and the most prominent difference is that the function declaration has a function name while the latter doesn't have one. Function DeclarationA function declaration also known as a function statement declares a function with a function keyword. The function declaration must have a function name.Function declaration does not require a variable assignment as they are standalone constructs and they cannot be nested inside a functional block.These are executed before any other code.The function in the function declaration can be accessed before and after the function definition.Syntax:function geeksforGeeks(paramA, paramB) { // Set of statements}Example: The following example illustrates a function declaration where we do the addition of two numbers. JavaScript // Function Declaration function geeksforGeeks(paramA, paramB) { return paramA + paramB; } let result = geeksforGeeks(5, 5); console.log('Sum=', result); OutputSum= 10 Function ExpressionA function Expression is similar to a function declaration without the function name.Function expressions can be stored in a variable assignment.Function expressions load and execute only when the program interpreter reaches the line of code.The function in the function expression can be accessed only after the function definition.Syntax:let geeksforGeeks= function(paramA, paramB) { // Set of statements}Example: The following example illustrates a function expression where we do the addition of two numbers. JavaScript let geeksforGeeks = function (paramA, paramB) { return paramA + paramB; } let result = geeksforGeeks(5, 5); console.log("Sum: ",result); OutputSum: 10 Difference between Function Declaration and Function ExpressionFunction DeclarationFunction ExpressionA function declaration must have a function name.A function expression is similar to a function declaration without the function name.Function declaration does not require a variable assignment. Function expressions can be stored in a variable assignment.These are executed before any other code.Function expressions load and execute only when the program interpreter reaches the line of code.The function in function declaration can be accessed before and after the function definition.The function in function expression can be accessed only after the function definition.Function declarations are hoistedFunction expressions are not hoistedSyntax: function geeksforGeeks(paramA, paramB) { // Set of statements }Syntax: var geeksforGeeks= function(paramA, paramB) { // Set of statements } Comment More infoAdvertise with us Next Article Difference between ‘function declaration’ and ‘function expression' in JavaScript rijushree100guha Follow Improve Article Tags : Difference Between JavaScript Web Technologies Blogathon Blogathon-2021 javascript-functions JavaScript-Questions Web Technologies - Difference Between +4 More Similar Reads Difference between function expression vs declaration in JavaScript 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 1 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 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 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 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 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 Explain the differences on the usage of foo between function foo() {} and var foo = function() {} Here we see the differences on the usage of foo between function foo() {} and var foo = function() {} types of function declarations in JavaScript. function foo() {} is a Normal Function or traditional general way of Function Declaration which every user or developer finds it simpler to declare and 4 min read Function Declaration vs. Function Definition Function Declaration introduces the name, return type, and parameters of a function to the compiler, while Function Definition provides the actual implementation or body of the function. Declarations enable calling the function elsewhere in the code, while definitions provide the code to be executed 2 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 forEach and for loop in Javascript In JavaScript, both forEach and for loops are used to iterate over arrays or collections, but they differ in usage and behavior. forEach is a higher-order function that simplifies iteration with built-in array methods, while for loops offer more control, flexibility, and broader application.For Loop 4 min read Like