Different type of function in JavaScript