While executing the below code in javascript:
var name=["Pankaj","Kumar"] ;
for( var i=0;i<name.length;i++)
{
console.log("Hello "+name[i]);
}
According to me ,it should output :
Hello Pankaj
Hello Kumar
But javascript engine outputs :
Hello P
Hello a
Hello n
Hello k
Hello a
Hello j
Hello ,
Hello K
Hello u
Hello m
Hello a
Hello r
If we change the name of array as names ,then it outputs according to expectations:
Hello Pankaj
Hello Kumar
name is not a javascript reserved keyword .
Could you please let me know the reason for this behavior.