Variables: -


Variable names can begin with uppercase alphabets, lowercase alphabets or dollar sign/symbol. Javascript does not allow the datatypes of the variable to be declared when a variable is created-variables are declared using var, command or keywords.
Syntax:
    var variablename:
        or
var variablename: value;
e.g. varnum=10;
    var num=2;
javascript is a case-sensitive languages.

Datatypes: Javascript supports four simple datatypes(Num), Boolean, String and (Null) and complex datatypes like Arrays and Objects.

Number Datatype: Number datatype consist of integers a floating point number. Numbers can be represented by decimal format, octal format and in hexa-decimal format.
e.g.
var n1= 12;
var n1= 13.567;
var n1= 2F5;
var n1= 0*5F;
String Datatype: A string is a sequence of zero or more characters that are enclosed in single or double quotes.
E.g.
var n1=“HTML Version 5”;
var n2=”Java”;
var n3=””;
var n4= “ “ ; // empty string
Boolean datatypes:
Boolean datatypes consist of logical values true and false. JavaScript automatically converts true values into 1 and false value into 0. When they are used in numerical expression.

Operators:
1.  Arithmetic Operators:
+    -    *    /    %    ++    --

2.  Logical operators:
&&    ||    !

3.  Comparison:
<    >    <=    >=    ==    !=    === (strictly equal to)
!=== (strictly not equal to) 
Strictly equal to (===): This operator checks the datatype of the variable as well as its value.
e.g.
var n1=”5”;
var n2=5;
(n1 == n2) returns true
(n1 === n2) returns false

4.  Assignment Operators:
=    +=    -=    *=    /=    %=

5.  String operators: currently javascript provides only one string operator also known as concatenation operator.
e.g.
var n1=”fyit”;
    var n2=n1 + “students”;
    values of n2 will be fyit students.
Placing text in a browser: Using JavaScript a string can he displayed using a browser from within an HTML file. The doc object in Java has a method, write(). For placing text in a browser. This method excepts a string has an argument and displays that string in the browser window. 

Syntax:
document.write(string);
e.g.
<head>
<script language=javascript>
document.write(“hello fyit”);
</script>
</head>
<body>
</body>
e.g.:
<html>
<head>
<script>
document.write(“Hello <br> <font color=blue> fy </font>”);
var.num=100;
document.write(“value of variable is <font face=nagenta size=6
color=green>” + num + “</font>”);
document.write(“<br> Square is <font face=magneta size=6 color=green> + (num * num) + “</font>”);
</script>

Post a Comment

0 Comments