我想要一个 JS 函数来说明是否设置了变量。我在下面定义了isset()。
如评论中所述,它的行为很奇怪。有任何想法吗?
<html>
<head></head>
<body>
<script type="text/javascript">
function isset(variableName) {
return typeof variableName != 'undefined';
}
a = 5;
console.log(isset(a));
console.log(isset(b)); // returns an error.
</script>
</body>
</html>