简体   繁体   中英

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';
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'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM