JavaScript / ECMAScript
Wrapper Boolean-Objekt
Beim Boolean-Objekt handelt es sich um ein Objekt, welches einen booleschen Wert kapselt und um Objektmethoden und Objekteigenschaften erweitert.
Ein Boolean-Objekt ist aber kein primitiver Datentyp. Es handelt sich hier um ein echtes Objekt.
Beispiel:
<script>
var a = true;
var b = new Boolean(true);
document.writeln(a + "<br>");
document.writeln("typeof(a) = " + typeof(a) + "<br>");
document.writeln(b + "<br>");
document.writeln("typeof(b) = " + typeof(b) + "<br>");
document.writeln("a == b: " + (a == b) + "<br>");
document.writeln("a === b: " + (a === b) + "<br>");
document.writeln("a.toString() = " + a.toString() + "<br>");
document.writeln("a.valueOf() = " + a.valueOf() + "<br>");
document.writeln("b.toString() = " + b.toString() + "<br>");
document.writeln("b.valueOf() = " + b.valueOf() + "<br>");
</script>
Ausgabe:
true
typeof(a) = boolean
true
typeof(b) = object
a == b: true
a === b: false
a.toString() = true
a.valueOf() = true
b.toString() = true
b.valueOf() = true