if 2 methods have same name and same number of parameters, which one will
be executed first?

 Posted by Ddd on 2/16/2011 | Category: JavaScript Interview questions | Views: 4095 | Points: 40
Answer:

The second method will be executed first

Code snippet.

<script>

function demo(s)
{
alert("first"+"---"+s);
}
function demo(s)
{
alert("Second"+"--"+s);
}
demo("javascript");
demo("jscript");
demo("jp");
</script>


output:
//In this example, the function with alert("Second"+"---"+s); statement will

//be executed 3 times, while the first function will not execute at all.


| Alert Moderator 

Comments or Responses

Posted by: Akiii on: 2/17/2011 | Points: 10
Please can you tell me how the second function is being called everytime?
Thank you

Akiii
Posted by: Ddd on: 2/17/2011 | Points: 10
demo("javascript");
demo("jscript");
demo("jp");

These 3 statements will make call to the second function everytime.
For further queries, please contact the publishers of this question.

Thanks.
Posted by: Ddd on: 2/17/2011 | Points: 10
demo("javascript");
demo("jscript");
demo("jp");

if the first function is moved down the order, it will be called 3 times.
So,logically the function mentioned last in the sequence will get the preference.
Posted by: Akiii on: 2/17/2011 | Points: 10
Thank you very much for the explanation Ddd...

Arka
Posted by: Ddd on: 2/17/2011 | Points: 10
How come 2 users Akii and Arka for the same post?
Kindly check the posts contents thorougly before publishing .
Thanks.
Posted by: Akiii on: 2/17/2011 | Points: 10
its me only......my nickname is Akiii.....
sorry for eh confusion..

Akiii

Login to post response