7 As can be seen, this is perfectly acceptable JavaScript programming When the value of an array element is replaced with a different value, there is no requirement for the replacement value to be of the same type. In the example below, array element 1 begins with the String "hello, is then changed
to the Boolean value false, and changed again to the number 3.1415: var things = new Array things = 21; things = "hello things = true things =
false things = 3.1415;
document.write("
[0]: " + things document.write("
[1]: " + things document.write("
[2]: " +
things As can be seen, this changing of array element values of different types works without problems We can confirm that a single array can store values of different types by displaying the return value of the typeof function:
var things = new Array things = 21; things = "hello things = true document.write("
type of things" + typeof things ); document.write("
type of things " + typeof things ); document.write("
type of things " + typeof things ); The output of
the above code is as follows Share with your friends: