How to test if a parameter is provided to a function?

后端 未结 8 1033
不知归路
不知归路 2020-12-13 03:45

I was wondering, can you create a function with an optional parameter.

Example:

function parameterTest(test)
{
   if exists(test)
   {
     alert(\'t         


        
8条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 04:10

    function parameterTest(bool)
    {
       if(typeof bool !== 'undefined')
       {
         alert('the parameter exists...');
       }
       else
       {
         alert('The parameter doesn\'t exist...');
       }
    }
    

提交回复
热议问题