Accepting Either One or No Arguments
<html> <head> <title>JavaScript Unleashed</title> <script type="text/javascript"> <!-- function welcomeMessage(userName) { if (userName != null) { document.writeln("Hello, " + userName); }else{ document.write("variable \"userName\" would show : "); document.writeln(userName); } } // --> </script> </head> <body> <script type="text/javascript"> <!-- document.writeln("First call to welcomeMessage(),\n"); welcomeMessage("Mr."); document.writeln("<HR>\nSecond call to welcomeMessage(),\n"); welcomeMessage(); // --> </script> </body> </html>