Skip to main content

Posts

Showing posts with the label What is the difference between the function declarations below?

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> Stayed Informed – Best JavaScript Interview Questions & Answers I hope you are enjoying with this post! Please share with you friends. Thank you!!