Since it is possible to do:
var x = 'foo', y = 'foo';
Would this also be possible?
var x, y = 'foo';
I tried it, however x becomes undefined.
I know this may seem like a silly or redundant question, but if I’m curious about something, why not ask? Also you will probably wonder why I would need two variables equal to the same thing in scope. That is not the point of the question. I’m just curious.
You need two separate statements to get the exact same semantics.
The solution other users are suggesting is not equivalent as it does not apply the
vartoy. If there is a global variableythen it will be overwritten.It is a good practice to correctly apply
varto local variables and not omit it for the sake of brevity.