Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

Java Script Class 2

Javascript base 2

Uploaded by

akashpk655
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Java Script Class 2

Javascript base 2

Uploaded by

akashpk655
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Variables in JavaScript

A variable is a memory location with a name. It can store a value and can be
modified during program execution. In JavaScript the keyword ‘var’ is used to
declare a variable. JavaScript determines the type of variable only when a value is
assigned to it.
Eg:
<html>
<head>
<title> JavaScript- Data Types</title>
</head>
<body>
<script language= “JavaScript”>
var P, Q, R;
P = 65;
Q = “India”;
R = false;
document.write(“Type of P is: “);
document.write(typeof(P));
document.write(“<br> Type of Q is: “);
document.write(typeof(Q));
document.write(“<br> Type of R is: “);
document.write(typeof(R));
</script>
</body>
</html>

Output Screen

JavaScript- Data Types X


Type of P is: number
Type of Q is: string
Type of R is : boolean

Client Side Scripting Using JavaScript- Class 2 Page 1


Operators in JavaScript
Almost all operators in JavaScript are similar to those in C++. JavaScript uses
different types of operators such as arithmetic operators, assignment operators,
relational operators, logical operators and string addition operator(+).

Arithmetic operators
Operator Operation Operator Operation
+ Addition % Modulus (division remainder)
- Subtraction ++ Increment
* Multiplication -- Decrement
/ Division

Relational operators (Comparison operators)


Operator Operation Operator Operation
== Equal to <= Less than or equal to
!= Not equal to > Greater than
< Less than >= Greater than or equal to

Logical operators
Operator Operation
&& AND
|| OR
! NOT

Assignment operators
Operator Operation Operator Operation
= Assignment *= Multiply and assignment
+= Add and assignment /= Divide and assignment
-= Minus and assignment %= Modulus and assignment

Client Side Scripting Using JavaScript- Class 2 Page 2


String Addition Operator (+)
The operator + is used to add two strings together. Adding two strings means
concatenating two strings. (In C++, the function ‘strcat()’ is used for the same.)

Eg:
<html>
<head>
<title> JavaScript- StringAddition</title>
</head>
<body>
<script language= “JavaScript”>
var x, y, z;
x = “Welcome to ”;
y = “The God’s Own Country”;
z = x + y;
document.write(z);
</script>
</body>
</html>

(The output screen will display ‘Welcome to The God’s Own Country’)

Client Side Scripting Using JavaScript- Class 2 Page 3

You might also like