Getting Started: Easy Way to Objects in Javascript

What are objects 

Let take a glance through variables in JavaScript,  const pie = 3.14, JavaScript variable can only contain a single value, in this example the value of variable name is 3.14.

Objects are also variables. Objects are variables that can contain more than one value, basically a collection of named values. 

let formObj = {
   name: value

Object has properties and methods and data are referenced by their name, Objects are also mutable in JavaScript.

Creating an object 

objects can be created using 

  • Object Literals
  • Constructor Functions
  • New Object() 
  • ES5 Objects Can Be Created Using The Object.Create().

Object literals is the best way to create an objects in JavaScript, in order to write clean and readable codes, use object literals to create an object.

object literals 

With object literals we can create an object this way

let person = { 
   name: ‘Ade’,
   address: ‘nigeria’,
   age: 45

values can be accessed by referencing to the name of the values contained in the object, in order to get the age of the person, we reference the value of the object through the age property. 

Person.Age //45

Object property 

Object properties are the named values in a object, they are referenced through there name, object property can be any primitive value,eg string, Boolean, number, null etc 

Object Method

Object methods are functions inside a object we will learn more about methods here, methods are also property of a object that contains a function definition. 

Let Person = { 
   name: ‘Ade’, 
   address: ‘Nigeria’, 
   age: 45, 

   getName: Function() {

Person.GetName(). //Ade

Leave a Comment

Your email address will not be published. Required fields are marked *