如何检查函数的未定义参数?(在JavaScript中)

如何检查函数的未定义参数?(在JavaScript中),javascript,function,undefined,arguments,Javascript,Function,Undefined,Arguments,有一些例子: a = ''; //string b = 0; //number 0 b1 = 0xf; //number 15 c = (function(){}) //function function (){} d = []; //object e = {}; //object [object Object] f = void(0); //undefined undefined 但当我尝试传递未定义的变量trougth函数时,如下所示: typeof qwerty; //undefined

有一些例子:

a = ''; //string
b = 0; //number 0
b1 = 0xf; //number 15
c = (function(){}) //function function (){}
d = []; //object
e = {}; //object [object Object]
f = void(0); //undefined undefined
但当我尝试传递未定义的变量trougth函数时,如下所示:

typeof qwerty; //undefined
function at(a){return (typeof a)+' '+a;}
at(qwerty); // ????
…我收到一个错误未捕获引用错误:未定义qwerty。 我怎样才能找到最短的方法来创建函数isDefineda、b或其他减少该表达式的技巧

c=(typeof a!='undefined'&&a||b)
澄清:如果定义了a,那么-c等于a,过度使用-b,就像php中的c=@a?:b一样

编辑:

然后:

var c = def( a, b );
// if a is defined - c equals a, otherwise b

抱歉,但你的问题是什么?帮你自己一个忙,在google.com上搜索“javascript中未定义的值”-只需阅读并尝试一下Tryit编辑器!你会找到正确的答案看到uncaughtreferenceerror:a没有定义Google Chrome 16…这是你调用函数的问题,你需要提供一些示例代码+所有这些示例都假设测试变量已经声明,不是吗?似乎在传递函数之前必须声明参数,但它可以是未定义的。它失败是因为在这种情况下a未定义&未声明-传递给函数的行为失败,因为js无法将符号a解析为任何内容。将检查移动到内联而不是函数;也看到
function def( a, b ) {
    var undef;

    return a === undef ? b : a;
}
var c = def( a, b );
// if a is defined - c equals a, otherwise b
function isDefined(variable, dflt) {
    return typeof variable === "undefined" ? dflt : variable;
}

var c = isDefined(a, b);