ShekarChandu Reddy wrote:Is that because both java and javascript follow different programming model?
Yes, Java and JavaScript have absolutely nothing to do with each other, despite the poor choice of naming.
With Java 8, which introduces some functional concepts, Java is moving towards being a functional language, but JavaScript has always been one.
What is concept behind that treating functions as objects in javascrpt and why?
Because JavaScript is a
functional language.
Read Part II of
Secrets of the JavaScript Ninja (2nd edition coming out soon!) for a detailed description of why functions are so important in JavaScript, and the advantages that being a functional language bring.
To summarize: it means that functions are
values, and can be treated just like any other values: stored in variables, passed as parameters, and so on.