What is the difference between the function declarations below?
var user = function () { //TODO: Some code }; And function country() { //TODO: Some code };
Answers:-
The main difference is the function user is defined at run-time whereas function country is defined at parse time.
For example as,
<script type="text/javascript"> //WHEN WE CALLING USER FUNCTION HERE WILL THROW AN ERROR. user(); var user = function(){ alert("Hello, I am a user!"); }; </script> <script type="text/javascript"> //WHEN WE CALLING USER FUNCTION HERE WILL NOT THROW AN ERROR. country(); function country(){
alert("Hello, I am a country!"); }; </script>