Does this line create global variables?
Does this line create global variables?
var first=second=third=fourth=fifth="Hello, ";
I'm not really sure how to test it :)
first
will be declared as a local variable and the rest will be global.
To fix this, try the following:
var first, second, third, fourth, fifth;
first = second = third = fourth = fifth = "Hello, ";
Or all on one line:
var first, second, third, fourth, fifth = fourth = third = second = first = "Hello, ";
Yes, everything except first
is global in this case. You can test your browser console by running
(function() { var x = y = 1; })();
console.log(y); // 1
You might want var y, x = y = 1;
First will be local, the rest will be global. See this script from the JS Fiddle .
Yes, this is to declare your variables first:
var first,second,third,fourth,fifth;
first=second=third=fourth=fifth="Hello, ";
Will do the same, except all the variables will be in the expected scope.
You only have a variable declaration with a name first
and four other variables are used without declaring them, so they are global.