Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I created the function in javascript like the below
JavaScript
function abc()
{
    // Something.
}

can i call that function like abc(10,10) or abc(20) is it possible?
Posted
Updated 5-Jun-12 21:11pm
v2

can i call that function like abc(10,10) or abc(20) is it possible?
Yes, you can - it's possible.

No error will be raised. Closest JavaScript method will be called. Thus, in your sample, for both abc(1) or abc(1,2) - abc() will be raised - it's just that you won't be able to use the passed/called parameters as the method invoked does not take that many parameters.

I have seen it working.
 
Share this answer
 
 
Share this answer
 
Comments
codeBegin 6-Jun-12 5:25am    
For Scholar member who downvoted my answer:
What is the problem with these links??
hi,
as you are giving parameter values to the function then you should have method accepting these no. of argument/parameters as
JavaScript
function abc(ist, second)
{
   alert(ist);
   alert(second);
}


then call this method like:

HTML
<input type="button" id="test" value="Test" onclick="abc('My name', 'address');" />
 
Share this answer
 
Comments
naveenvenkanna 6-Jun-12 3:22am    
I defined the funtion without parameters. But am calling that function using Arguments. Is it possible to call in such a way.
tanweer 6-Jun-12 3:24am    
answer is NO. how you can get the parameter inside the function as it not taking any thing from out side.
Sandeep Mewara 6-Jun-12 5:33am    
Not correct. You can call. Javascript allows.
tanweer 6-Jun-12 7:00am    
even you call a method that does not have any parameter with parameters what is the use of those parameters that are called??
Sandeep Mewara 6-Jun-12 7:12am    
No use. But that's entirely different thing. As such, it's not an error and the thing is possible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900