Data types in
JavaScript
Computer is mainly used to store information
and to do complex calculations. when we store information it is in the form of
alphabets , numbers or alphanumeric values. JavaScript provides data type to
store and use different types of values that are:
1.Number type : numerical values specially belongs to the ‘number’ data type. Number data type stores both whole number or decimal points numbers which stores fractional part of number .Number data type can hold positive as well as negative values.
|
Example : Var y=100000 Var z=-67.99 |
2.String type : Strings are used for storing text.Strings must be inside of either double or single quotes.
|
Example : Var x=”hello” Var z=’Information
technology’ |
3.Boolen type :
It
represents only two values ‘true’ and ‘false’ . all relational , conditional and logical
operators produce Boolean values
true/false or yes/no.
4. Infinity : Division by 0 gives you another
special value.
|
Example : A=3/0 Result :infinity |
5. Null : In JavaScript null is just a value
which means “nothing ”,”empty”. ”unknown”.
It is supposed to be something that doesn’t
exist.
6.undefined : JavaScript returns ‘undefined’
when variables which is declared but not assigned . then java interpreter shows
that it is undefined.
|
Example : Var age; Alert(age); |
Operators
Operators are used to do arithmetic and logical operations
,operations that require one operand is called as unary operator and operators
that requires two ope rands are called as binary operators . most of the operators
can be divided into groups : Arithmetic, Relational and logical operators
Arithmetic operators :
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra
. for following example consider :
Var a=40 , b=4.5;
|
Operators |
Definition |
example |
result |
|
+ |
Addition |
a+b
|
44.5 |
|
- |
Subtraction |
a-b
|
35.5 |
|
* |
Multiplication |
a*b
|
180 |
|
/ |
Division |
a/b
|
8.89 |
|
% |
Modulus(it returns reminder after division) |
a%b
|
4 |
A simple multiplication code:
<!doctype html>
<html>
<head>
<title>multiplication</title>
</head>
<body bgcolor=yellow>
<h1>program to calculate multiplicationof two
numbers</h1>
<script language="javascript">
var a,b,c;
a=76;
b=99.45;
c=a*b;
document.write("<br><h1>multiplication of two
numbers:"+c+"</h1>");
</script>
</body>
</html>
output:

Comments