Jump to content

Declare a variable


tobeyt23

Recommended Posts

Considering this topic is in the Javascript forum, the correct answer is no, you cannot. Javascript has no concept of default values for function parameters. What you have to do is check whether the parameter was defined and if not, set the default.

 

function someFunction(bob){
   if (bob === undefined){ bob = true; }

   //...
}
Link to comment
https://forums.phpfreaks.com/topic/293199-declare-a-variable/#findComment-1500213
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.