Press "Enter" to skip to content

A brief Note on JavaScript Objects – JavaScript articles

JavaScript is an Object Oriented Programming language (OOP). An Object is a special kind of data and acts like real –life objects. An object has properties and methods. A real-life example for object could be a music system. It has properties like, on, off, current volume, etc. The methods could be said as, turn on, turn off, increase volume, etc. Similarly, JavaScript objects do have properties and methods.

Properties:

Properties are the values associated with an Object.

Example: stringObject.length
NOTE: ”. length” is a property which is associated with a string Object.

Methods:

Methods could be said as the action which can be performed on an object.

Example: stringObject.link(url)
NOTE: “.link()” is an action which is used to make a string Object into a link.

 

Kinds of JavaScript Objects

There are mainly 6 types of built-in Objects in Javascript. They are, string Object, date Object, Boolean Object, array Object, math Object and RegExp Objects.

JavaScript String Object

A string Object is used to manipulate a stored piece of Text.
Examples:

String Object Properties: .length, .prototype
String Object Methods:
big(), toUpperCase(), match();

Syntax for creating a String object:

var myStr=new String(string);

JavaScript Date Object

Date Object is used to work with dates and times.
Examples:

Date Object Properties: .constructor, .prototype
Date Object Methods:
Date(), getDate(), getDay()

Syntax for creating a Date object:

var myDate=new Date();

JavaScript Array Object

Array Objects are used to store multiple values in a single variable. An Array can hold more than one value at a time.
 
Examples

Array Object Properties: .length, .prototype,
Array Object Methods:
.concant(), .join()

Syntax for creating an Array object:

var myColors=new Array("red”,”blue","green")

JavaScript Boolean Object

Boolean Object is used to convert a non-boolean value into a Boolean value. ( True /False).
Examples

Boolean Object Properties: .constructor, .prototype
Boolean Object Methods:
.toString(),.valueOf()

Syntax for Creating a Boolean Object:

Var myBoolean = new Boolean(value);

JavaScript Math Object

Math Objects are used to perform mathematical tasks.
Examples

Math Object Properties: .SQRT1_2, .SQRT2
Math Object methods:
.round(x),.max(x,y)

Syntax for Creating a Math Object:

All properties and methods of Math can be called by using Math as an object without creating it, because math object is not a constructor.

JavaScript RegExp Object

The RegExp Obejct is used for “What” to search in the “text”. RegExp is the short for Regular Expression. We can use to search for a pattern inside a text. RegExp is used to strore a pattern.
 
Examples

RegExp Object Properties: .global, .ignoreCase
RegExp Object Methods:
.test(), .exec(), .compile();

Syntax for creating a RegExp Object:

var txt=new RegExp(pattern,attributes);
 OR
 var txt=/pattern/attributes;