1 of 14

Web Technologies

Java Script Objects

Smt M.Jeevana Sujitha

Assistant Professor

Department of Computer Science and Engineering

SRKR Engineering College, Bhimavaram, A.P. - 534204

2 of 14

OBJECTIVES

The Objectives of this lecture are

  • To learn about JS Objects.

3 of 14

Java Script Objects

  • Java script is referred as an object based programming language.
  • Every object consists

of properties and

behaviors.

  • Properties are values associated with an object.
  • Behaviors or methods are the actions that can be performed on objects.
  • Example:

var name=“srinu”; document.write(name.length); document.write(name.toUpperCase());

4 of 14

Java Script Objects

  • Various objects in Java script are
  • Date
  • String
  • Array
  • Boolean
  • Math
  • RegExp

5 of 14

Java Script Objects

Date object: This object is used for obtaining the date and time.

  • This date and time is based on computer’s local time or it can be based on GMT(Greenwich Mean Time).
  • Now a days GMT is also called as UTC(Universal Coordinated Time)

6 of 14

Java Script Objects

Methods of Date object:

  • getDate(): Returns current date based on local computer

time

  • getDay(): Returns current Day. Number is from 0 to 6 i,e

from sun to sat

  • getTime(): It returns the time
  • getHours(): It returns the hour value ranging from 0 to 23 based on local time
  • getMinutes(): Returns the minute value ranging from 0 to 59.
  • getSeconds(): Returns the seconds value ranging from 0 to

59.

  • getMilliseconds(): Returns milliseconds ranging from 0 to

999 based on local time.

7 of 14

Java Script Objects

Methods of Date object:

  • getUTCDate(): Returns current date obtained from UTC
  • getUTCDay(): Returns current Day based on UTC. Number

is from 0 to 6 i,e from sun to sat

  • getUTCHours(): It returns the hour value ranging from 0

to 23 based on UTC timing zone

  • getUTCMinutes(): Returns the minute value ranging from 0 to 59 on UTC timing zone.
  • getUTCSeconds(): Returns the seconds value ranging from 0 to 59 on UTC timing zone.
  • setDate(value): to set desired date using local time or UTC

timing zone.

  • setHour(hr,min,sec,ms): to set desired time.

8 of 14

Java Script Objects

String object: String is a collection of characters.

Methods:

  • concat(str): It concatenates the two strings.
  • charAt(indexval): returns the character specified by index value.
  • substring(beg,end): returns sub string specified by beg and end char

9 of 14

Java Script Objects

Methods:

letters into lower case.

  • toUpperCase(): It converts
  • toLowerCase(): It converts all upper case

all lower case

letters into upper case.

Example:

var s1=“sri”; var s2=“nivas”;

document.write(s1.concat(s2)); document.write(s1.charAt(1)); document.write(s1.toUpperCase());

10 of 14

Java Script Objects

Boolean object: This is used when we want to represent true and false values.

Example:

var tmp=new Boolean(false);

11 of 14

Java Script Objects

Math object: This is used for performing mathematical computations.

Methods:

  • sqrt(num): Finds the square root of a num
  • abs(num): Returns absolute value of a num
  • ceil(num): Returns the ceil of a num Ex: ceil(10.5);
  • floor(num): Returns the floor of a num Ex: floor(10.5)
  • log(num): Returns log value of a num
  • pow(a,b): Returns power value Ex: pow(2,5)

12 of 14

Java Script Objects

Methods:

  • min(a,b): Returns min value of a and b Ex: min(2,4)
  • max(a,b): Returns max value of a and b Ex: max(2,4)
  • exp(num): Returns exp value
  • sin(num):
  • cos(num): Returns cos value of a num
  • tan(num):

13 of 14

Java Script Objects

Array object: In Java script array is treated as an object.

  • Array is a collection of similar type of elements which can

be referred by a common name.

Array Declaration:

  • In java script the array can be created using Array

object.

Syntax:

var arrname=new Array(size);

Example:

var a=new Array(5);

Initialization:

var a=new Array(10,20,30,40,50);

var a=[10,20,30,40,50];

14 of 14

THANK YOU