Asynchronous JavaScript and XML

What is the difference between the function declarations below?

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>


I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^