Converts a non-zero value to Boolean type in JavaScript

Description

The following code shows how to converts a non-zero value to Boolean type.

Example


<!--from  ww w .  ja  v a2  s  . c  o  m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var anInt = 1;
var aBoolean = Boolean(anInt);
document.writeln(aBoolean);
</script>
</head>
<body>

</body>
</html>

Click to view the demo

The code above generates the following result.

Converts a non-zero value to Boolean type in JavaScript