There are examples here with C++ and Java but it'll be great if someone can explain this with JavaScript examples. Also how is definition Vs. declaration works for variables.
Asked
Active
Viewed 935 times
-1
-
https://kangax.github.io/nfe/ – SLaks Jun 30 '15 at 19:13
-
@Kyll If I am not wrong that question is about difference between function declaration Vs. expression. Whereas I am looking for clarification between declaration Vs. definition (not expression).... assuming there is any. – Adi Jun 30 '15 at 19:19
-
We call both function *declarations* and *expressions* a "function definition", and both variable *declarations* and *initialisations* a "variable definition". It's not a standardised term, though. – Bergi Jun 30 '15 at 19:20
-
Unlike C, Javascript has no notion of function declarations as distinct from definitions. – SLaks Jun 30 '15 at 19:24
-
To add some context... At about 2:20 on this video https://youtu.be/KRm-h6vcpxs?t=2m8s the author makes this statement... "Parentheses around the function that causes the parser to treat it not as a function declaration but as a definition". Hence my curiosity if there is any difference between declaration Vs. definition? @Bergi – Adi Jun 30 '15 at 19:24
-
2@Adi: In that case, it's a mistake and he meant "expression". That's even what the text says on the slide - twice. – Bergi Jun 30 '15 at 19:25
-
Thanks @Bergi - now I can move on with my life :) – Adi Jun 30 '15 at 19:28
1 Answers
3
There is no notion of "function definitions" in JavaScript. It does only distinguish between function declarations and function expressions (and the deprecated function statements).
When we use the term "definition", it's typically meant as a hyperonym for both.
It's similar for variables: there's only the term variable declaration in the standard, and when we use "variable definition" we either refer to that or the initialisation of the variable with a value (or both).