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

后端 未结 8 1034
不知归路
不知归路 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 03:51

    best way to check: if the param is not undefined

    function parameterTest(param) {
        if (param !== undefined)
        ...
    

    the param could be also a variable or a function name

提交回复
热议问题