How to set default values for parameters of a JavaScript function and call it with less parameters?
<p>I have a function </p>

<pre><code>function test(name)
{

}
</code></pre>

<p>I call it with <code>test("kanishka");</code></p>

<p>In one case, I want to pass two parameters (<code>name</code> and <code>age</code>) to this function: </p>

<pre><code>test("kanishka",27);
</code></pre>

<p>In PHP, I can do this by setting a default value to <code>age</code> :</p>

<pre><code>test(name , age = NULL)
</code></pre>

<p>Is there any way in JavaScript to do this?</p>

<p>I tried </p>

<pre><code>test(name , age = NULL) 
</code></pre>

<p>but it gives errors.</p>

<p>I can declare 2 functions</p>

<pre><code>test(name) and  test(name , age = NULL)
</code></pre>

<p>but it duplicates the code.</p>

<p>Or I can change my previous function call which took one parameter to two parameters, giving a  default value for <code>age</code>: </p>

<pre><code>test("kanishka" , 0)
</code></pre>

<p>but in this case I have to find all function call and change them.</p>
