Page 1 of 1

JS: var vs. let?

Posted: Thu Nov 06, 2008 7:08 am
by Commander McLane
Sorry for the stupid question.

Browsing through different JS-scripts I see that locally used variables are sometimes declared with var and sometimes with let, and myself I seem to have used them quite interchangeably. However, I seem to recall Ahruman explaining that one of them is not good and discouraged for some reason. But which?

EDIT: And while I am posting this, Safari quits unexpectedly and violently. Oops? Have I pissed off the invisible powers of programming??? :shock: :shock: :shock:

Posted: Fri Nov 14, 2008 8:58 am
by Commander McLane
No answers? So JS just doesn't care?

Posted: Fri Nov 14, 2008 9:53 am
by Eric Walch
let is added to the is vocabulary in a later JS version. It wasn't always there. In most cases both are interchangeable. let is a bit more local valid. You can redefine a value within a loop with a let statement and it starts using the old value after the loop. But in this way we never use it.

When you look inside the widgets on a mac you see that they are also programmed in JS (At least a large part of them). There you only see the use of var. let is never used and according to Ahruman its use could change or end in future.

Posted: Fri Nov 14, 2008 10:10 am
by Commander McLane
Thanks for clarifying! So 'var' it is.

"And your word shall be 'var'. 'Let' shall not be your word, but 'var' shall be your word."