zq29 Posted October 22, 2006 Share Posted October 22, 2006 When creating a function in PHP, you can set default values for arguments within a function like so:[code]my_function($name="unknown",$age) { echo "Hello, my name is $name, I am $age";}[/code]I am trying to do the same for a function in JavaScript, but don't appear to be having much luck - Google isn't being very helpful either...Thanks guys Quote Link to comment Share on other sites More sharing options...
fenway Posted October 22, 2006 Share Posted October 22, 2006 Such an option doesn't exist... in fact, I've never seen anything like this. Generally, it's preferable to simply default the values at the top of the subroutine; so for JS:[code]function my_function( name, age ) { if( name == null ) name = "unknown"; alert( 'Hello, my name is ' + name + ', I am ' + age );}[/code] Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 22, 2006 Author Share Posted October 22, 2006 *Slaps forehead*I was overlooking the obvious there! Many thanks Fenway :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.