Convert a empty string to Boolean type in JavaScript

Description

The following code shows how to convert a empty string to Boolean type.

Example


<!--from w  w w.  j  av 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 a empty string to Boolean type in JavaScript