What is the difference between function declaration and function definition in javascript? Can we have one example for the same? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between function declaration and function definition in javascript? Can we have one example for the same?

15th Feb 2017, 5:48 AM
Vipul Pathe
Vipul Pathe - avatar
1 Answer
+ 2
In JS, there is no "declaration" of function distinct from "definition", as you do in C, Java... So there's no difference. Otherwise, in JS, we distinct function "declarations" from function "expressions" ( "function fn() { }" vs "var fn = function() { };" ), and the term "definition" usually stand for both ( as well, both variable declarations and initialisations are called "variable definitions" ).
15th Feb 2017, 10:25 AM
visph
visph - avatar