How to pass the value 'undefined' to a function with multiple parameters?

前端 未结 12 2221
滥情空心
滥情空心 2020-12-14 14:26

I want to pass the value of \'undefined\' on a multiple parameter function but without omitting the parameter.

What do I mean with \"without omitting the paramet

12条回答
  •  余生分开走
    2020-12-14 14:37

    The void operator seems to be the most common way to explicitly get undefined.

    You would use it like this in your example:

    myFunction(void 0, "abc");
    

    It's also a reliable method for comparing against undefined that is guarded against undefined being accidentally overridden in older JavaScript environments:

    var x;
    if (x === void 0) {
        // this will execute
    }
    

提交回复
热议问题