CodesJava

Easy learning with example program codes

javascript data types and variable scope tutorial


JavaScript Data Types:

JavaScript Data Types are the type of values that can be represented and manipulated by JavaScript.

JavaScript Data Types List:

1. Numbers.
2. Strings.
3. Boolean.
4. Null.
5. Undefined.
6. Object.
7. Array.
8. RegExp.

JavaScript variables:

Variable is the name of reserved memory location. In JavaScript var keyword is used to declare a variable.

Rules for declaring a JavaScript variable:

1. JavaScript variable name must begin with a letter, underscore, or dollar sign.
2. JavaScript variable names are case sensitive.
3. JavaScript reserved keywords like abstract, boolean etc can’t be used as JavaScript variable name.

JavaScript variable scope:

1. Local variable.
2. Global variable.

JavaScript Local variable:

A variable defined inside a function or block of JavaScript code is known as a local variable. It can be accessed only within that function or block.

JavaScript Local Variable Example:

<html>
<head> 
<script>  
function showNumber(){
//local variable    
var num=10;
document.write(num);  
}  
showNumber();
</script> 
</head>
<body>
</body>
</html>

Try it:

JS Bin on jsbin.com

JavaScript Global variable:

A variable defined outside a function or block of JavaScript code is known as a global variable. It can be accessed anywhere in JavaScript code

JavaScript Global Variable Example:

<script>  
<html>
<head> 
<script>  
//Global variable    
var num=10;
function showNumber(){
document.writeln(num);  
}  
function displayNumber(){
document.writeln(num);  
}  
showNumber();
displayNumber();
</script> 
</head>
<body>
</body>
</html>

Try it:

JS Bin on jsbin.com
 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki