Ryenski
Ryenski

Reputation: 9692

Javascript variable declaration one-line vs two-line syntax

We often see variables declared on one line before they are initialized with a value. We also often see variables declared and initialized in one statement. Is there any difference or advantage or disadvantage of one over the other? Is there any difference between the following two statements?

var foo;
foo = 'bar';

vs.

var foo = 'bar';

Upvotes: 0

Views: 73

Answers (1)

Avinash Malhotra
Avinash Malhotra

Reputation: 556

var foo;    // value of foo is undefined
foo='bar';  // var foo value is overwrites with string bar.

Initial value of foo was undefined, but later-on changed to 'bar'.

Upvotes: 1

Related Questions