Doing the same in javascript