javascriptconceptual

Function declaration vs function definition JS


What is difference between function declaration and function definition in JavaScript? I read chapter 5.3.2 from this book

When nested, however, function declarations may only appear at the top level of the function they are nested within. That is, function definitions may not appear within if statements, while loops, or any other statements.

but don't understand difference between declaration and definition... Please, explain it ( note: I understand difference between function expression and function declaration!)


Solution

  • In this case, they are just using two different terms to refer to the same thing. The official* term is "function declaration".

    Source for official is page 98 of the ECMAScript standard.