/    Sign up×
Community /Pin to ProfileBookmark

How does var work? Quick question

Hello guys,

I have a .js file resembling something like

[code]
var currentaddress=””;

function getURL(username)
{
if(username==”john”)
{ currentaddress = “www.google.com”;}
else
{ currentaddress = “www.yahoo.com”;}
}
[/code]

My question is, assuming that 100 users are running this .js file, each user will have their own copy of currentaddress, is this correct? I won’t have just one copy which keeps changing depending on who was the username the last time it was called.

Thanks much.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jul 01.2009 — JavaScript only runs in the browser, so 100 different browsers will have 100 different versions of that file.
Copy linkTweet thisAlerts:
@hacketJul 02.2009 — It gets instantiated each time it's called, so no, the values will not carry over.
Copy linkTweet thisAlerts:
@PembarauthorJul 02.2009 — Thanks guys
×

Success!

Help @Pembar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...