4

Here is the piece of code

str = "a,b,c";
name = str.split(",");

The name variable shows up as 'object' type in Firefox and 'string' type in chrome Why is that happening ? Here is the jsfiddle http://jsfiddle.net/XujYT/17/

Also the name variable stores the value "a,b,c" instead of the split array in chrome http://jsfiddle.net/XujYT/23/

asked Nov 17, 2012 at 9:35

1 Answer 1

13

Because name is a global variable used by chrome, and it’s not possible to override it without unexpected results. Try:

var name = str.split(","); // always use var for local variables!
answered Nov 17, 2012 at 9:37
Sign up to request clarification or add additional context in comments.

6 Comments

@David Wow ! I never knew that . Any Idea what is that variable used for ?
@Sethunath: to store the window name used by window.open to open this window.
@Sethunath: any reason not using var in the first place?
@Jan-StefanJanetzky no . var name would do . I was just curious to know what was going on
@Sethunath the global name variable is not meant to be manipulated, and it doesn’t behave like regular variables. F.ex, if you assign something to it it will evaluate that value as toString(), so name={} will evaluate to "[object Object]".
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.