www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript Variables Scope Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49

In the last lesson we learned about the basics of JavaScript variables. In this lesson we will continue our discussion of JavaScript variables. In this lesson we will learn about JavaScript variable scope.

Variables scope defines where in the code a variable can legally be used. The scope of a variable depends on the fact that where ther variable was originally declared or initialized. A variable declared inside a function block { } cannot be accessed outside the function block. On the contrary when we declare or initialize a variable outside a function block { } it has a global scope. Any variable having a global scope is accessible to whole code within the same document. Its lifetime starts when it is declared and ends when the web page ends.

There is a special case, though, the variables declared inside a function block without the var keyword have global scope. However, they become accessible only after the function containing them is invoked.

An example follows:

<script type="text/JavaScript">
var site = "Pickatutorial.com";     //GLOBAL

function test( ) {
tutorial = "JavaScript Tutorial";             //GLOBAL
var lesson = "JavaScript Variable Scope";             //LOCAL
}


Next >>> Lesson No. 6: JavaScript Arithmetic





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.