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

Javascript

JavaScript, originally developed by Netscape as LiveScript, has evolved significantly since its inception in 1995, with a standard established as ECMA-262. It is a dynamically typed language distinct from Java, lacking support for object-oriented development, and is primarily used for client-server interactions on the web. JavaScript enables event-driven computation, allowing user interactions to trigger actions, and includes various features such as primitive types, operators, and built-in objects like Math and String.

Uploaded by

shreyassupe346
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)
2 views

Javascript

JavaScript, originally developed by Netscape as LiveScript, has evolved significantly since its inception in 1995, with a standard established as ECMA-262. It is a dynamically typed language distinct from Java, lacking support for object-oriented development, and is primarily used for client-server interactions on the web. JavaScript enables event-driven computation, allowing user interactions to trigger actions, and includes various features such as primitive types, operators, and built-in objects like Math and String.

Uploaded by

shreyassupe346
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/ 28

JAVASCRIPT

Origins

⚫ JavaScript was originally named Live script was


developed by Netscape .
⚫ In late 1995 Live script became a joint venture of
Netscape and Sun Microsystems.
⚫ Netscape’s JavaScript has gone through extensive
evolution, primarily by adding many new features.
⚫ A language standard for JavaScript was developed
in the late 1990s by European Computer
Manufacturers Association as ECMA-262.
⚫ Microsoft JavaScript is named as Jscript.
Javascript and Java

⚫ JavaScript and Java are actually very different.

Javascript Java

JavaScript does not support the


Java supports object-oriented
object-oriented software
paradigm.
development paradigm

Dynamically typed language. Java is a strongly typed language.

JavaScript objects are dynamic. Objects in Java are Static.


Uses of JavaScript

⚫ The original goal of JavaScript was to provide


programming capability at both the server and the
client ends of a web connection.
⚫ Interactions with users through form elements such
as buttons and menus can be conveniently described
in JavaScript.
⚫ Events such as button clicks and mouse movements
are easily detected with JavaScript, they can be used
to trigger computations and provide feedback to the
user.
⚫ Capability of JavaScript was made possible by the
development of the Document Object Model, which
allows JavaScript to access and modify the CSS
properties and content of any element of a displayed
HTML document.
Event Driven Computation

⚫ JavaScript are event driven, meaning that the actions


are executed in response to actions of the users of
documents.
⚫ One use of JavaScript is to check the values provided
in forms by users to determine whether the values
are sensible.
Browsers and HTML/JavaScript Documents

⚫ When a JavaScript script is encountered in the


document,the browser uses its JavaScript interpreter
to “execute” the script.
⚫ When the end of the script is reached,the browser
goes back to reading the HTML document and
displaying its content.
⚫ JavaScript scripts can appear in either part of an
document, head or body depending on the purpose
of the script.
⚫ Scripts that produce content only when requested or
that react to user interactions are placed in the head
of the document.
⚫ Scripts that are to be interpreted just once, when the
interpreter finds them, are placed in the document
body.
Object Orientation and JavaScript

⚫ JavaScript Objects
In JavaScript, object are collections of properties.
Each property is either a data property or a function or
method property
Data Properties
.

Primitive values References to other


objects.
General Syntactic Characteristics.

⚫ Scripts can appear directly as the content of a


<script> tag.
⚫ The type attribute must be set to “text/javascript”
⚫ The JavaScript script can be indirectly embedded in
the HTMl document using the src attribute of a
<script>tag,whose value is the name of a file that
contains the script.
⚫ <script type=“text/javascript src=“demo.js”>
</script>
JavaScript Identifiers

⚫ They must begin with aletter,an underscore or a


dollar sign.
⚫ Letters in a variable name in JavaScript are case
sensitive.
JavaScript Comments

⚫ JavaScript has two types of comments


⚫ a)Whenever two adjacent slashes(//) appear on a
line, the rest line is considered a comment.
⚫ Second both single and multiple line comments can
be written using /* to introduce the comment and */
to terminate it.
Primitives,Operations and Expressions
Primitive Types

Primitive Types

Number String Boolean Undefined Null


Numeric and String Literals

⚫ All numeric literals are values of type Number.


⚫ The numeric values of JavaScript are represented
internally in double-precision floating point form.
Declaring Variables

⚫ JavaScript are dynamically typed. This means that a


variable can be used for anything.
⚫ The variable can have the value of a primitive type or
it can be a reference to any object.

⚫ Example var counter=0;


Numeric Operators

JavaScript Operators

Binary Operators Unary Operators


Example:-,+,/,* (--,++)
The Math Object

⚫ The Math object provides a collection of properties


of Number objects and methods that operate on
Number objects.
Methods in Math Object

sin(x) cos(x) floor(x) round(x) max(x) min(x)


The number Object

⚫ The number object includes a collection of useful


properties that have constant values.

Property Meaning
MAX_VALUE Largest representable number
MIN_VALUE Smallest representable number
NaN Not a number
POSITIVE_INFINITY Special value to represent infinity
NEGATIVE_INFINITY Special value to represent
negative infinity
The String Catenation Operator.

⚫ String Catenation is specified with the operator


denoted by a plus sign(+).
Implicit Type Conversion

⚫ The JavaScript interpreter performs several different


implicit type conversions. Such conversions are
called coercions.
⚫ When a value of one type is used in a position that
requires a value of a different type, JavaScript
attempts to convert the value to the type that is
required.
⚫ Example: If either operand of a + operator is a string,
the operator is interpreted as a string catenation
operator.
⚫ Example “August” +1999
⚫ Example 2: 7* “3”
In the above expression the operator is one that is
only used with numbers. This forces numeric context
on the right operand.Therefore,JavaScript attempts
to convert it to a number.The answer is 21.
Explicit Type Conversions

⚫ There are several different ways to force type


conversions, primarily between strings and numbers.
⚫ Strings that contain numbers can be converted to
numbers with the String constructor
var str_value=String(value);
⚫ Conversion can also be done with toString method.
var num=6;
var str_value=num.toString();
var str_value_binary=num.toString(2);

Javascript has two predefined string functions


1)parseInt
2)parseFloat.
⚫ parseInt
The parseInt function searches the string for an
integer literal.If one is found at the beginning of the
string,it is converted to a number and returned.
parseFloat:
It searches for a floating point literal.
String Properties and Methods

You might also like