C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Variable scoping in Java script


Posted Date: 10 Oct 2008    Resource Type: Code Snippets    Category: Javascript

Posted By: Bindu Bujji       Member Level: Gold
Rating:     Points: 10



This example showed how globally and locally declared and scoped variables are seen from inside and outside a function.

Below need to put in script tag of the HEAD TAG

var aNewVariable = "is global.";
function doSomething(incomingBits) {
alert("Global variable within the function is : " + aNewVariable);
alert("Local variable within the function is : " + incomingBits);
}


Now in the script tag which is Inside the BODY tag.


doSomething("is a local variable");
alert("Global var outside the function: " + aNewVariable);
alert("Local var outside the function: " + incomingBits);


The output is like this..it display in alert box though.
=======================================================
Global Variable wtihin the function is: is global
Local variable within the function is: is a local variable
Global var outside the function: is global






Responses

Author: Pradeep Y    24 Oct 2008Member Level: Gold   Points : 1
hi Bindu,

Please also explain how the program works.

Regards,
Pradeep


Author: Bindu Bujji    30 Oct 2008Member Level: Gold   Points : 2
Hi Pradeep,
The alert box messages itself tells you the scope of the variable. If you don't understand, pl get back to me.....

This is just scope of the variable inside the function and outside the function. Try yourself using some numbers, u will get more idea.



Author: Pradeep Y    31 Oct 2008Member Level: Gold   Points : 0
hi bindu,

Thanks for your reply...

TC


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Variable scoping in Java Script  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: for…in Loop in Javascript
Previous Resource: obtaining input with confirm() in java script
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

UK Conference calling Company

Contact Us    Privacy Policy    Terms Of Use