Difference between ‘function declaration’ and ‘function expression' in JavaScript Last Updated : 03 Jan, 2024 Suggest changes Share 17 Likes 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 } R rijushree100guha Follow 17 Article Tags : Difference Between JavaScript Web Technologies Blogathon Blogathon-2021 javascript-functions JavaScript-Questions Web Technologies - Difference Between +4 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like