We can set a default value for an argument passed to a function so that if an argument is not passed, there will still be a value for it. This can be used when a common value is required for a function and you are wanting to leave it out when calling the function.
In PHP
This can be done in PHP by setting an argument to a value when declaring the function.
Example
< ?php function testFunction($var1, $var2 = true) { // do something here... if ($var2=='true'){echo $var1;} } testFunction('my message'); // will print 'my message' testFunction('my message',false); // will not print anything ?> |
In Javascript
Doing the same thing in Javascript is a little more difficult. There are two methods that I am familiar with. The first is not 100% bullet proof and will not work under certain situations. Read More » »

