Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redeclaring a javascript variable

In this tutorial there is written:

If you redeclare a JavaScript variable, it will not lose its value.

Why should I redeclare a variable? Is it practical in some situations?

thank you

like image 343
xralf Avatar asked Jul 31 '11 09:07

xralf


1 Answers

It's nothing more than a reminder that if you do this:

var x=5; var x; alert(x); 

Result will be 5.

If you re-declare variable in some other languages for example - result will be undefined, or NaN, but not in javascript.

like image 175
ThatGuy Avatar answered Sep 29 '22 12:09

ThatGuy