Javascript On December 4, 1995, Netscape and Sun Inc. Jointly Introduced
Javascript On December 4, 1995, Netscape and Sun Inc. Jointly Introduced
ADVANTAGES
An Interpreted Language
Embedded within HTML
Minimal Syntax – Easy to learn
Quick Development
Designed for simple, small programs
Performance
Procedural Capabilities
Designed for Programming user events
Easy Debugging and Testing
Platform Independence
Syntax:
Every variable has a data type that indicates what kind of data the
variable holds. The basic data types in JavaScript are Strings,
Numbers, and Booleans.
A string is a list of characters, and a string literal is indicated by
enclosing the characters in single or double quotes. Strings may
contain a single character or multiple characters, including whitespace
and special characters such as \n (the newline).
Numbers can be integer or floating-point numerical value and
numeric literals are specified in the natural way.
Boolean can be any one of two values: true or false. Boolean literals
are indicated by using true or false directly in the source code.
Syntax:
var<variablename>= value;
DATA TYPES
Arithmetic Operators
Arithmetic operators are the most familiar operators because they are
used everyday to solve common math calculations. JavaScript
supports all the basic arithmetic operators like
addition (+),
subtraction (–),
multiplication (*),
division (/), and
modulus (%, also known as the remainder operator).
++ Increment
- - Decrement
Assignment Operator
An assignment operator is the operator used to assign a new value to
a variable. Some assignment operators are combined with other
operators to perform a computation on the value.
1 = - a=10
2 += - b += 5
3 -= - c -= 3
4 *= - d *= 2
5 /= - e /=2
6 %= - f%=4
Relational or Comparison Operators:
Relational operators are also called as Comparison operators, they
compares two values and the result is true or false. JavaScript
provides a rich set of relational operators including
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to),
>= (greater than or equal to).
Using a relational operator in an expression causes the expression to
evaluate as true if the condition holds or false if otherwise.
Logical Operators:
Logical operators perform logical (boolean) operations. Logical
operators combine or invert boolean values. Once comparisons are
made, the logical operators can be used to create more complex
conditions
&&(AND),
|| (OR)
! (NOT).
For && (AND) the result is false if the first operand is false;
otherwise, the result is the Boolean value of the second operand.
For || (OR) the result is true if the first operand is true; otherwise, the
result is the Boolean value of the second operand.
For ! (NOT) the result is true if the operand is false; otherwise, the
result is true.
String Operators:
One of the built-in features of JavaScript is the ability to concatenate
strings. The + operator performs addition on numbers but also serves
as the concatenation operator for strings. + operator which is also
called as the string concatenation operator.
Eg:“ab” + “bc” = abbc
The syntax is
Prompt Dialog Box: The prompt dialog box is very useful when the
user want to pop-up a text box to get user input. Thus, it enables you
to interact with the user. The user needs to fill in the text box field
and then click OK.
Syntax:
prompt(“message”, “<default value>”);
Eg:
prompt(“enter the name”, “abitha”);
Conditional Statements
Like other Programming languages, PHP also allows to write code
that perform different actions based on the results of a logical or a
test Condition. Thus you can create test conditions in the form of
expressions that evaluates to either true or false and based on these
results you can perform certain actions The following statements in
PHP help us to make decisions:
● if Statement
● if...else Statement
● if...elseif....else Statement
● switch Statement
If statement in PHP:
If statement executes a statement or a group of statements
if a specific condition is satisfied as per the users expectation. This is
the simplest PHP’s conditional statement and can be written in the
following form.
Syntax:
if (condition)
{
Statement(s); }
If else statement in PHP:
The if statement evaluates a condition and executes a set of code if the
condition is true and another set of code if the condition is false.
Syntax:
if (condition)
{
Statement(s) if condition is true;
}
else
{
Statement(s) if condition is false;
}
if (Condition 1)
{
Statement(s) if condition 1 is true;
}
elseif(Condition 2)
{
Statement(s) if condition 2 is true;
}
else
{
Statement(s) if both conditions are false;}
Switch Case:
The switch case is an alternative to the if..elseif..else statement which
executes a block of code corresponding to the match.
Syntax:
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
Looping Structure:
Loop structures in PHP is an iterative control structures that involves
executive the same block of code a specified number of times. Loops
that iterate for fixed no of times is also called as Bounded loops. PHP
supports four types of loops.
● for Loop
● While Loop
● Do While Loop
For Loop:
The for loop is used when you know how many times you want to
execute a statement or block of statements.
Syntax:
for (init counter; test counter; increment counter)
{
code to be executed;
}
Parameters:
● init counter: Initialize the loop initial counter value
● Test counter: Evaluated for every iteration of the loop. If it
evaluates to TRUE, the loop continues. If it evaluates to FALSE, the
loop ends.
● Increment counter: Increases the loop counter value.
While Loop:
The while loop executes a block of code as long as the condition
specified in the while statement evaluates to true
Syntax:
Syntax:
do
{
code to be executed;
}
while (condition is true);
FUNCTIONS IN JAVASCRIPT:
1. functions are javascript code that perform a specific task
and often return a value
2. a javascript function may take 0 or more parameters.
3. parameters are a standard technique via which control data can be passed to a
function
4. control data passed to function, offers a means of controlling what a function
returns.