/

HTML / CSS / JavaScript Tutorial

JavaScript Boolean method: valueOf()

[this page | pdf | back links]

The valueOf() method (when applied to a JavaScript Boolean variable) returns the primitive value of the Boolean (i.e. itself).

 

It has the following syntax (with no parameters):

 

boolean.valueOf()

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
var h = Boolean(2>1)
document.getElementById("Example").innerHTML =
  'var h = Boolean(2>1);<br>' +
  'var x = h.valueOf();';
document.getElementById("Result").innerHTML = h.valueOf();
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodBooleanValueOf() {
  var x = document.createElement("CANVAS"); var c = x.getContext("2d"); return !!c.alueOf;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Booleans


Desktop view | Switch to Mobile