19 Years of Excellence 99% Hiring Rate

JavaScript Objects – A Complete Guide

ADMEC Multimedia Institute > Web Design > JavaScript Objects – A Complete Guide

Ehila! folks this is Abhishek Sinha, pursuing Web Master Plus Course here in ADMEC Multimedia Institute Rohini New Delhi. I have recently completed part of my designing program and as part of the project I was given to write a blog on the topic “What are objects in JavaScript”. This is topic is far more important than the reader realizes and I’ll tell you why but first the introductions.

What is JavaScript?

JavaScript as the name clearly states is a scripting language and a lot of beginners mix it with Java let me tell you one thing here they both are different and have no link to each other even remotely. Like car and carpet and have nothing common except for the few words likewise is for JavaScript. Java is server-side language whereas the JavaScript is client- side and server- side language. JavaScript is dynamic and more versatile than Java and is easier to learn.

Do you want to know about Java? Read Out – Know What Makes Java a so Important Language

This client-side language has a lot in it but we’ll learn here about from Web Designing and Development’s perspective.

JavaScript follows camel case format and is strictly case sensitive which means word or code written in capitalizing, lowercase, uppercase so beginner has to be cautious about it. It also follows ECMA specifications.

JavaScript acts as an integral part of the webpage without which yes a webpage can be designed but will not be friendly as this boy here makes it. See a lot of designers use this language because it makes it easier for them on both side I mean on client-side and server-side where Node JS and others come in handy to use.

What are User Defined Objects?

Now coming to the topic well nearly everything predefined in JavaScript is basically the objects I mean literally everything, they all have their prototypes. We use them to store multiple data in a very along with its fields user-defined objects are defined using object literals (these two gentlemen {}) while defining them space and line breaks are ignored.

How to Create One?

There are various ways to make an object let me show you one by one:

// 1
var student = { firstName:"Abhishek", lastName:"Sinha ", age:18 };

// 2
var student = { firstName: "Abhishek", lastName: "Sinha", age: 18, };

The thing to note here I could give age values in quotes, it depends on how you are going use a particular value if stated in quotes then it will act as a string and if not then as a number.

firstName, lastName, age are the property of the student and Abhishek Sinha 18 are its values.

Objects are called as a constructor in the places needed.

Let’s say I want to alert the firstName of the student then I would simply write :

alert(student.firstName);

simple as that huh.

now if one wants to store these values in the variable :

var store = student.firstName;

That’s all for the user-defined ones.

Predefined Objects in JavaScript

One might be wondering how this all makes up for part where I said nearly everything in JavaScript are an object so let’s see to it.

These are all part of the core JavaScript:

  • Array Object
  • Boolean Object
  • Date Object
  • Function Object
  • Math Object
  • Number Object
  • RegEx Object
  • String Object

That’s all I can think of. All these objects have methods and properties as every other object in this cosmos has. Let’s touch the surface of these also shall we:

Array object

Arrays are the global objects which are used to store multiple values at once and these values are specified with a particular index number which, yes it starts from zero. Example:

var animals = [dog, cat, monkey];

Boolean object

Boolean as always has represents two values true and false. By default it has undefined.

Date object

Date object here is the way of getting the date in JavaScript which uses Unix Time Stamp, an integer value counted in milliseconds from 1 January 1970 UTC. When one calls date object it won’t return you the date or anything it simply gives the milliseconds to till time. For attaining the particular date and time one has to calculate it.

Function object

Till now I guess you would have understood the concept of a function here everything you do in here is using the function. Function objects are created using the function constructor which in itself is very broad but for general:

A constructor is something which is directly on provoking the function related to it and if it doesn’t have any values it returns undefined. Function objects created inside the function constructor is always parsed.

Have Some Idea About the JavaScript’s Projects

Math object

Math is an object which is used for mathematical constant and function. This object does not any constructor. All type of mathematical operations can be done using this object.

Number object

Number is a function which is mostly used to parse any value to number as it says. This object is repetitively used with inputs as by default all its values are strings. If it is unable to parse the value then it returns NaN, meaning Not a Number. By default, it treats the value as float and if a user wishes to change that one can use ‘parseInt’ which parses the values to integer format. Whereas parseFloat is used for getting it back to float format or decimal format.

RegExp object

RegExp here is used to create patterns, not the design pattern, one with codes type a set of text which is used to match to the required field.

Now the RegExp is created using two types of notations:

  • Literal Notations
  • Constructor
Literal Notation

Literal Notation is compiled when the regular expression created is evaluated or runs. Ex:

var here = /abc/g;
Constructor

The constructor objects provide runtime compilation of the created regular expressions. Ex:

var here = new RegExp(/abc/g);

Now before using this, there are several parameters you might have to learn before usage. These parameters help in defining the base of the pattern.

String object

String object is used for created a sequence of words which can be used checking the string basically matching and things.

Let’s Learn JavaScript Course from Experts!!

The objects are one of the most important components which one can’t ignore while learning the JavaScript course; you may have learned the part of the objects without knowing it.

Related Posts

Leave a Reply

Talk to Us