added documentation and code in javascript