JS: var vs. let?

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

JS: var vs. let?

Post 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:
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

No answers? So JS just doesn't care?
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post 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.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post 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."
Post Reply