0% found this document useful (0 votes)
55 views

Javascript On December 4, 1995, Netscape and Sun Inc. Jointly Introduced

JavaScript was jointly introduced by Netscape and Sun Inc. in 1995. It allows creation of interactive web pages and bridges the gap between HTML and server-side CGI programs. JavaScript has many advantages like being an interpreted language, being embedded within HTML, having minimal syntax, and providing procedural capabilities. It is used for programming user events and is platform independent. JavaScript variables can store values and have data types like strings, numbers, and booleans. Common operators in JavaScript include arithmetic, assignment, relational, logical, and string operators. Conditional and looping statements like if/else, switch/case, for, while, and do-while allow control flow. Functions are blocks of JavaScript code that perform tasks and can take parameters.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Javascript On December 4, 1995, Netscape and Sun Inc. Jointly Introduced

JavaScript was jointly introduced by Netscape and Sun Inc. in 1995. It allows creation of interactive web pages and bridges the gap between HTML and server-side CGI programs. JavaScript has many advantages like being an interpreted language, being embedded within HTML, having minimal syntax, and providing procedural capabilities. It is used for programming user events and is platform independent. JavaScript variables can store values and have data types like strings, numbers, and booleans. Common operators in JavaScript include arithmetic, assignment, relational, logical, and string operators. Conditional and looping statements like if/else, switch/case, for, while, and do-while allow control flow. Functions are blocks of JavaScript code that perform tasks and can take parameters.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

JAVASCRIPT

On December 4, 1995, Netscape and Sun Inc. jointly introduced


JavaScript 1.0. Javascript is an object oriented language that allows
creation of interactive web pages. Javascript is embedded into an
HTML program JavaScript had truly bridged the gap between the
simple world of HTML and the more complex Common Gateway
Interface (CGI) programs on the Server. The JavaScript client-side
technology provides many advantages over traditional CGI Server-
side scripts. Though JavaScript is a case-sensitive language. It is
good programming practice to type the command in lowercase.
JavaScript uses the semicolon (;) to separate statements.

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:

<script language="javascript" >


JavaScript code
</script>
JavaScript Variables:
Variable is a memory location where value can be stored. Variable is
a symbolic name for a value. Variables are declared with the var
keyword in JavaScript. Variable names can begin with an
uppercaseletter(A –Z), lowercaseletter(a – z),underscore character(_)
or dollar sign ($).

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

Primitive Data type:


1String ( values enclosed in single or double quotes)
2Number
* Integer
a Decimal
b Hexadecimal
c Octal
* Floating
* Special NaN (not a number) value
3Boolean ( true and false )
4Null
Complex type:
1Arrays
2Object

Operators and Expressions:


An operator is used to transform one or morevalues into a single
resultant value.(+ - * /)

The values to which the operator is applied isreferred to as


Operands.(1 any symbol 2)

A combination of an Operator and itsoperands is referred to as an


expression.(1+2=3)

There are three types of expressions as follows,


Arithmetic expressions
Relational expressions
Logical expressions

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

Conditional Operator (?:)


The ?: is the conditional operator in JavaScript, which requires three
operands, hence it is called the ternary operator.

The syntax is

var variablename=(condition) ? value1 : value2;

Placing text in a Browser


The Document object in javascript has a method write() for placing
text in a browser.
Syntax:
Objectname.methodname
Eg:
Document.write(“test”);

Dialog boxes in java

Alert Dialog Box: An alert dialog box is mostly used to give a


warning message to the users. For example, if one input field requires
to enter some text but the user does not provide any input, then as a
part of validation, you can use an alert box to give a warning message.
Alert box gives only one button "OK" to select and proceed.
Syntax:
alert(“message”) ;
eg:
alert(“welcome”);

Confirm Dialog Box: A confirmation dialog box is mostly used to


take user's consent on any option. It displays a dialog box with two
buttons: OK and Cancel. If the user clicks on the OK button, the
confirm() will return true. If the user clicks on the Cancel button, then
confirm() returns false.
Syntax:
confirm(“message”);
eg:
confirm(“do you want to exit”);

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 elseif else statement in PHP:


If-elseif-else statement is a combination of if-else statement. Here
multiple conditions can be checked and action is based on the result
of the condition.
Syntax:

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:

while (condition is true)


{
code to be executed;
}
Do While Loop:
The do while loop is always very similer to the while loop but
executes the block of code at least once before evaluating the
condition. Here the condition is evaluated only at the time of exit of
each iteration

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.

You might also like