I’m tryig to create a array named status in my javascript, but it is not working in Google Chrome.
<html>
<body>
<script>
var array = [1, 2, 3];
document.write("Type of [" + array + "] : " + (typeof array) + "<br />");
document.write("Value of array.length : " + array.length + "<br />");
document.write("<br /><br />");
var status = [1, 2, 3];
document.write("Type of [" + status + "] : " + (typeof status) + "<br />");
document.write("Value of status.length : " + status.length + "<br />");
</script>
</body>
</html>
In the above piece of code even though I’m assigning an array value to the variable status In chrome the value is considered as of type string.
Is it a bug with Chrome or a valid behaviour?
This issue is already answered here.
If you try the above given code it works as expected because the scope of the variable status is limited to the local scope of the method status. In your sample the scope of the variable was global(scope is window).