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();

 var country = function(){
    alert("Hello, I am a country!");
 };
</script>


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

About blogger..

ANIL SINGH

Hey! I am Anil Singh. I am Active Blogger, Writer and Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
http://www.code-sample.com
http://www.code-sample.xyz

Post a Comment
www.code-sample.com/. Powered by Blogger.