Convert undefined to boolean value with Boolean in JavaScript

Description

The following code shows how to convert undefined to boolean value with Boolean.

Example


<!--from  www.  ja  v  a 2 s. c o m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var aString;
var aBoolean = Boolean(aString);
document.writeln(aBoolean);
</script>
</head>
<body>

</body>
</html>

Click to view the demo

The code above generates the following result.

Convert undefined to boolean value with Boolean in JavaScript