JS function definition in if statement test