When i executed following JavaScript code, i got undefined
var ns=new String('hello world');
String.prototype.capitalAll=function(){
                                 this.toUpperCase()
                                       };
alert(ns.capitalAll()); // undefined
But, when i add return, it returns a value
var ns=new String('hello world');
String.prototype.capitalAll=function(){
                                 return this.toUpperCase() // added return
                                       };
alert(ns.capitalAll()); // HELLO WORLD
Why return is required here and in end of every function. I have seen use of return in many javascript frameworks.