menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Function D...
source image

Dev

1w

read

332

img
dot

Image Credit: Dev

Function Declaration & Function Expression

  • Function declarations, or function statements, declare a function using the function keyword with a designated function name.
  • Function declarations do not require variable assignment and are standalone constructs that can be accessed before or after their definition.
  • Function declarations are hoisted and executed before other code in the program.
  • The function within a function declaration can be accessed both before and after its definition.
  • Example: function functionName() { // set of statements }
  • Function expressions are similar to function declarations but do not have a function name and can be stored in a variable assignment.
  • Function expressions are executed only when the program interpreter reaches the line of code where they are defined.
  • The function in a function expression can only be accessed after its definition.
  • Example: let variableName = function(param1, param2) { // set of statements }
  • console.log(variableName(args1, args2));
  • Reference link: https://www.geeksforgeeks.org/javascript/difference-between-function-declaration-and-function-expression-in-javascript/

Read Full Article

like

20 Likes

For uninterrupted reading, download the app