Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


JavaScript Programming

JavaScript > Code Examples

A Function Can Be Set Up to Accept a Variable Number of Arguments

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
A Function Can Be Set Up to Accept a Variable Number of Arguments <html> <head> <title>A Function Can Be Set Up to Accept a Variable Number of Arguments - Happy Codings :-)</title> <script type="text/javascript"> <!-- function welcomeMessage(userName) { if (userName != null) { document.writeln("Hello, " + userName); }else{ document.writeln("Happy Codings :-) C++, C#, HTML, Java, JavaScript Code Examples!"); } numArgs = welcomeMessage.arguments.length; if(numArgs > 1) { for(var i = 1; i < numArgs; i++) { document.writeln("\""+welcomeMessage.arguments[i]+"\""); } } } // --> </script> </head> <body> <script type="text/javascript"> <!-- var userName = "Jhon", extraMsg = "It has been a long time!"; var userName2 = null; var extraMsg1 = "Why dont you come here?"; var extraMsg2 = "You can enjoy!"; welcomeMessage(userName, extraMsg); document.writeln("<hr>"); welcomeMessage(userName2, extraMsg1, extraMsg2); // --> </script> </body> </html>