document.writeln() calls toString() in JavaScript

Description

The following code shows how to document.writeln() calls toString().

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var tutorial1 = {<!--   w  w  w .ja v  a 2s  .  c o m-->
toLocaleString : function () {
return "Java";
},

toString : function() {
return "XML";
}
};

var tutorial2 = {
toLocaleString : function () {
return "HTML";
},

toString : function() {
return "CSS";
}
};

var tutorial = [tutorial1, tutorial2];
document.writeln(tutorial.toString());

</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

document.writeln() calls toString() in JavaScript