Output :
Properties and methods of object's ore
accessed with " operator. JavaScript
supports 2types of objects built-in objects
Program tocheck number is prime or not
Enter vour Number (Greater than one):-31
check plme umber
and user defined objects.
1. Built in objects such as Math, String,
Array, Date etc.
2. JavaScript gives facility to create user
defined objects as per user
requirements. The 'new' keyword is
used to create new object in JavaScript.
Number ls prime
e.g.
d=new Date();
ohects in JavaSeript 1/'d' is new instance created for Dateobject.
BavaScript is an object based scripting
language. Almost everything is an object DeM(Document Object Model) :
in JavaScript. A JavaScript object is an When HTML document is loaded into
entity having state (properties) and a web browser, it becomes a document
behavior (methods). An object can group object. It defines logical structure of
data together with functions needed to document. The way in which HTML
manipulate it. Look around you, you will document content is accessed and
find many examples ofreal world objects. modified is called as Document Object
Such as table, board, television, bicycle, Model. It is programming interface for
shop, bus, car, monitor etc. All these HTML and XML (Extensible Markup
tangible things are known as objects. Language) documents.
Take an example of car object. It has The standardization of DOM was
properties like name, model, weight, founded by W3C (World Wide Web
color etc. and methods like start, stop, Consortium) which works for
brake etc. All cars·have same properties standardization of web technologies.
but contain different values from car to According to W3C :
car. All cars have same methods but
perform differently. "The W3C Document Object Model
|Object Properties Methods (DOM) is a platform and language
[Link]-Ferrari [Link])
neutral interface that allows programs
[Link]-F430 [Link]) and scripts to dyn amically access and
Car
car. [Link]() update the content, structure, and style of
a document. "
[Link]-red [Link])
440
3.4JavaScript Event
that occurs on the webpage.
Events are actions done by the user or an application
(onKeypress, onKeydown,
In previous year we studied different kevboard events
onkeyup) and mouse events (onClick, onMousemove, onMouseout, onMouseover).
Similarly there are some more events used with form objects.
Input andother object Events:
Event handler Deseription
onblur It occurs when user leaves field or losses focus of an element.
onfocus Itoccurs when an element gets focus.
onchange |It occurs when user changes content of an element or selects
dropdown value. E.g. for textbox,password, select box, textarea
etc.
onselect It occurs when user selects some text of an element.
onsubmit It occurs when user clicks submit button.
onreset It occurs when user clicks reset button.
onload It occurs when page/image has been loaded.
onunload It occurs when document/page has been unloaded or closes.
point. With eXaCt digits
Object:
An array is an object
Ised to store multiple that can store a collection
values in single of items. JavaScript
can hold more th an one value varigble. An arrays are
array isa special variable
to store large
at a time. A
Arrays which
amounts of data of the same become really useful when you need
as given below. type. You can create an
array in JavaScript
var
fruits-["Mango","Apple","Orange" ,"Grapes"]:
OR
var fruitS=new
Array("Mango","Apple",
You can access and set the items in "Orange","Grapes");
the index of the first element of an an array by referring to its indexnumber
array is zero. arrayname[O] is the first and
arrayname[1] is second element and soon. element,
e.g. var fruitname-fruits[0]:
[Link]("demo"),inner HTML=fruits[ 1];
roperty Description
index The property represents the zero-based index of the match in the strina
|length Reflect number of elements in array.
ethod Description
| concat() Joins two or more arrays, and returns a copy of the joined arrays
copyWithin() Copies array elements within the array, to and from specied positions.
Method
Description
find() Returns the value of the
first
in testing. element in an arTay that satisfies a test
forEach() Calls a function for each array element.
indexOf() |Search the array for an
isArray(0 element and returns its position.
Checks whether an object is an array.
|pop) Removes the last element of an
push) array, and returns that element.
Adds new elements to the end of an array, and
reverse) Reverses the returns the new length.
order of the elements in an array.
sort() Sorts the elements of an array.
Program Using array objec