JS-101-Fundamentals
  • JavaScript Library
  • 1-JavaScript Fundamentals
    • 0-Getting Started
      • Welcome
    • 1-JS-Fundamentals
      • 1-Grammar and Types
        • Comments
        • Declarations
        • Scope
        • Hoisting
        • Types
        • Literals
      • 2-Control Flow and Error Handling
        • if
        • if else
        • switch
        • try catch
        • throw
      • 3-Loops
        • For Loops
        • For In Loops
        • For Of Loops
        • Do While
        • While Loops
      • 4-Functions
        • Declarations
        • Expressions
        • Calling Functions
        • Scope
        • Parameters
        • Arguments
        • Closures
        • Closures Challenge
        • Arrow Functions
        • Predefined
      • 5-Expressions and Operators
        • Assignment
        • Comparison
        • Ternary
        • Typeof
        • Left Hand Side
        • Spread
      • 6 Numbers and Dates
        • Numbers
          • Numbers Enhanced
        • Math
        • Dates
      • 7 String Methods
        • String Literals
        • Methods
      • 8 Regular Expressions
        • Basic Intro
      • 9 Arrays
        • Array Review
        • Populating/Referring
        • Length
        • Iterating
        • Methods
      • 10 Objects
        • About Objects
        • Properties
        • Enumeration
        • Initializers
        • Constructor Functions
        • this
        • create
        • Methods
      • 11 ES6 Intro
        • ES6 Intro
        • let
        • const
Powered by GitBook
On this page
  • File Location
  • How Objects are Created
  • Practice
  • Challenge
  1. 1-JavaScript Fundamentals
  2. 1-JS-Fundamentals
  3. 10 Objects

Initializers

File Location

We will be working in the following file:

    javascript-library
        └── 0-PreWork
        └── 1-Fundamentals
            └── 11-Objects
                01-properties.js
                02-enumeration.js
                03-initializers.js <----You will be working in this file.

How Objects are Created

To create an object in JavaScript, there are a few different options. From the MDN docs: "Objects can be initialized using new Object(), Object.create(), or using the literal notation (initializer notation)." Using the literal notation gives more control and flexibility over what goes inside of it. Most objects you've created so far have been done with the initializer notation.

Below are two ways to create a similar object.

// Object is created using the literal notation.
let johnSmith = {
    firstName: "John",
    lastName: "Smith",
    age: 25,
    eyeColor: 'blue'
};
// Object is created using Object()
var janeDoe = new Object();
person.firstName = "Jane";
person.lastName = "Doe";
person.age = 21;
person.eyeColor = "brown";

Practice

Create an object using the literal/initializer notation, and create one object using Object().

Challenge

Research and create an object using Object.create().

PreviousEnumerationNextConstructor Functions

Last updated 7 years ago