L4 Data Types Variable (1.3)
L4 Data Types Variable (1.3)
P R O G R A M : IN F O R M ATI O N T E C H N O L O G Y ( N B A
A C C R E D ITED )
S E M E S T ER : V
N A M E O F FA C U LTY: M S . Y O G I TA J O R E
Unit 1 :
Basics of JavaScript
Programming
(12 M)
P R O G R A M : IN F O R M ATI O N T E C H N O L O G Y ( N B A
A C C R E D ITED )
: V
N A M E O F FA C U LTY: M S . E M A I L :
y o g it a . k h a n d a g a le@v p t . e d u . in
Basics of JavaScript
Programming
1.1 Features of JavaScript
1.2 Object Name, Property, Method, Dot Syntax, Main Event
1.3 Values and Variables
1.4 Operators and Expressions
1.5 if statement , if…else. If…elseif, Nested if
1.6 switch… case statement
1.7 Loop statement
1.8 Querying and setting properties and Deleting properties,
Property Getters and Setters
1.3 Values and Variables
A JavaScript variable is simply a name of storage location.
Two types of variables in JavaScript :
local variable
global variable.
There are some rules while declaring a JavaScript variable (also
known as identifiers).
Name must start with a letter (a to z or A to Z), underscore( _ ), or
dollar( $ ) sign.
After first letter we can use digits (0 to 9), for example value1.
JavaScript variables are case sensitive, for example x and X are
different variables.
Local Variables
A JavaScript local variable is declared inside block or function.
It is accessible within the function or block only.
For example:
<script> <script>
function abc() If(10<13)
{ {
var x=10; var y=20;//JavaScript local variable
Variable
Value of is
x isx
} }
</script> 10(Local) </script>
Global Variables
A JavaScript global variable is accessible from any function.
A variable i.e. declared outside the function or declared with window
object is known as global variable.
For example:
<html> function b()
<body> {
<script> document.write(data);
var data=200; //gloabal }
variable a(); //calling JavaScript
function a() function
{ b();
document.write(data); </script>
} </body> 200 200
</html>
Global Variables
A JavaScript global variable is declared outside the function or
declared with window object.
It can be accessed from any function.
For example:
<html> a();
<body> </script>
<script> </body>
var value=50; //global variable </html>
function a()
{
alert(value);
}
Data Types
JavaScript provides different data types to hold different types of
values.
There are two types of data types in JavaScript:
1.Primitive data type
2.Non-primitive (reference) data type/ Composit Data Types
JavaScript is a dynamic type language, means you don't need to
specify type of the variable.
You need to use var here to specify the data type.
It can hold any type of values such as numbers, strings etc.
For example: var a=40;//holding number
var b=“Info Technology”//holding string
Data Types
JavaScript Data
Types
<script>
// It is single line comment
document.write("hello javascript");
</script>
Types of JavaScript Comments
There are two types of comments in JavaScript.
2. Multi-line Comment
<script>
/* It is multi line comment.
It will not be displayed */
document.write("example of javascript multiline comment");
</script>
Quiz Time !
Q1. A ________is simply a name of storage location.
Ans : JavaScript Variable
Ans : Primitive
Non- Primitive
Quiz
https://forms.office.com/Pages/DesignPage.aspx?auth
_pvr=OrgId&[email protected]
&origin=shell#FormId=QEUap70T20yz690UXwrJwIuVSI
KHZ3RDo4EeJ2CYjgFUNjhLQ1hVMEVNTkVVQUtKWUxC
S1JVSzcwRy4u