I want a JS function that says whether a variable is set. I've defined isset() below.
It behaves strangely as described in the comments. Any ideas?
<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>
variableNameis not the same asvarname. Why try to access an undeclared variable?true.