Type assertion in javascript