educative.io

Insert method of trie class

Why does the insert(String(arr[x]), x) taking in 2 arguments when the function definition has only 1 parameter (key).

A Javascript function can be correctly called with a variable number of arguments since arguments can be optional. It also allows you to adapt to the type of the arguments and perform the relevant operations. This behavior is quite different from some of the hard-typed languages but it can be quite useful.

P.S. You may remove the second argument and the code will still execute successfully since the first arguement is the only one of interest.