alert(nameOfName); // or
document.getElementById("anyelementid").innerHTML=nameOfName; //should also trigger error because we are trying to put array in place of string.
alert with an object value (arrays are objects, just a special case), it automatically calls
toString on that value.
var arr = [1, 2, 3]; // Notice that they show the same result alert(arr); alert(arr.toString());
// Converts the number to a string console.log(1 + '2'); // Converts the booleans values to numbers console.log(true + true);