Intro to Custom JS Objects

Published on: March 11, 2017

Hey there! Welcome to the 38th Easy JavaScript tutorial, part of EasyProgramming.net. Let's get deeper into object-oriented programming and learn about creating custom JavaScript objects!

Objects follow the JSON format. They are encased in curly braces and can contain strings, numbers, boolean, arrays, other objects, null, and custom functions known as methods. The data within the object is separated by commas (like array items).

Syntax of an object:

var person = {
        "id" : "1",
        "name" : "Nazmus",
        "title" : "Developer",
        "social" : {
            "website" : "EasyProgramming.net",
            "facebook" : "facebook.com/EasyProgrammingNet"
        }
        method1 = function(){
            //write what method1 does
        }
    };
  

Reading Object Data

    person.name

    person.social.website

    person['title']

To fork the fiddle and follow along: https://jsfiddle.net/easyjs/bm47n4ce/

 

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:



Comments: