Java script variable question
What is the difference between a variable in java script declared with "var" keyword and without using var keyword in .net .aspx page??
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ranjit PowarRank #553 · 4.4K reputationPosted Feb 6, 2016, 10:13 PM EST
Krishna Rajput SinghRank #605 · 4K reputationPosted Feb 6, 2016, 6:32 AM EST
Rajeesh MenothRank #118 · 18.4K reputationPosted Feb 6, 2016, 6:34 AM EST
.Net also using var keyword.
More details refer the following article :
http://www.c-sharpcorner.com/UploadFile/5ef30d/var-keyword-in-C-Sharp-programming/
Chandan Kumar Sahoo69 reputationPosted Feb 6, 2016, 6:56 AM EST
Abhay ShankerRank #375 · 6.7K reputationPosted Feb 6, 2016, 7:27 AM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 6, 2016, 7:33 AM EST
In JavaScript:
In your first example, 'a' is being instantiated and set within the function scope. In your second example, 'a' is being set outside the function scope (most likely window.a).
With
var:var a = "A" (function(){ var a = "B" alert(a) //B })() alert(a); //AWithout
var:var a = "A"; (function(){ a = "B" alert(a) //B })() alert(a) //BVivek KumarRank #272 · 9.3K reputationPosted Feb 6, 2016, 8:53 PM EST