×

JavaScript Objects

Object Creation using Object Literal

An object is a standalone entity that stores multiple values as properties and methods. JavaScript objects are used to represent real-world entities such as Employee, Student, Product, Customer, etc.

Beginner 30 Minutes Monopoly IT Solutions Updated 2026-08-02
JavaScript class training banner
5.0
5.0
4.6
Overview

What you'll cover

Learning objectives

  • Understand JavaScript Objects
  • Create objects using Object Literal
  • Access object properties
  • Create object methods
  • Create nested objects
  • Use Object.keys()
  • Use Object.values()
  • Check property existence using hasOwnProperty()

Prerequisites

  • Variables
  • Functions
  • Arrays
  • Basic JavaScript

Related topics

  • Object Constructor
  • Constructor Functions
  • Object.create()
  • Classes
  • JSON
Theory

Concept breakdown

What is an Object?

An object is a standalone entity that stores multiple values in the form of properties and methods.

Properties

Properties are key-value pairs that store data.

Methods

Methods are functions stored inside an object.

Nested Objects

Objects can contain other objects as properties.

Syntax
Hands-on example

Object Creation using Object Literal

Console Output
Walkthrough

Step by step

  1. 1

    Create Object

    Create an employee object using curly braces.

  2. 2

    Add Properties

    Add firstName and lastName properties.

  3. 3

    Add Method

    Create getFullName() method to return the employee's full name.

  4. 4

    Nested Object

    Create an address object inside the employee object.

  5. 5

    Check Property

    Use hasOwnProperty() to determine whether mobile exists.

  6. 6

    Add New Property

    If mobile does not exist, add it dynamically.

  7. 7

    Display Object

    Print the object, keys, values and employee details.

Summary

Key takeaways

Key points

  • Object Literal is the simplest way to create objects.
  • Properties are stored as key-value pairs.
  • Objects can contain methods.
  • Objects can contain nested objects.
  • Properties can be added dynamically.
  • Object.keys() returns property names.
  • Object.values() returns property values.
  • The this keyword refers to the current object.

Advantages

  • Easy to read
  • Easy to write
  • Fast object creation
  • Supports nested objects
  • Supports methods
  • Most commonly used approach

Disadvantages

  • Not suitable when creating many similar objects.
  • Constructor functions or classes are better for reusable object blueprints.
Real-world use

Employee Management System

Every employee can be represented as an object containing personal information, address, salary, department, and methods such as getFullName() or calculateSalary().

Interview prep

Frequently asked questions

An Object Literal is the simplest way to create an object using curly braces.

Object Literal uses {}, whereas Object Constructor uses new Object(). Object Literal is shorter and more commonly used.

It returns an array containing all property names.

It returns an array containing all property values.

It checks whether a property exists directly on the object.

Test yourself

Quick MCQ practice

1. Which is the simplest way to create an object?

2. Which method returns property names?

3. Which method checks whether a property exists?

Apply it

Practice on your own

Coding exercise

Student Object

Create a Student object using Object Literal with name, age, course, marks, address, and getDetails() method.

Assignment

  1. Create a Product object.
  2. Add Product ID, Name, Price, Category.
  3. Create a Manufacturer nested object.
  4. Create getProductInfo() method.
  5. Display all details using document.write().

Tags

#javascript#object-literal#objects#beginner#json#oop

getintouch

Book for Live Demo!