2

I've a javascript variable and running it in my firefox console.

var name = ['manish','google'];
alert(name[0]);

The result of above alert is m

But If rewrite the code as below

var names = ['manish','google'];
alert(names[0]);

Then it alerts manish

Can anyone please let me know that what is the reason behind this?

Manish Jangir
  • 5,329
  • 4
  • 42
  • 75

1 Answers1

0

name is a property of the window object. Check this out

console.log(name); shows that name is recognized as a String not an Array.

Console Output:

manish,google

Use a different variable name if you are in the global scope...

brso05
  • 13,142
  • 2
  • 21
  • 40