function snippet for javascript