How to Create a Simple Object in JavaScript?

Estimated read time 1 min read

Here is an example to create a simple object in JavaScript:

var person = {
  firstName: "John",
  lastName: "Doe",
  age: 30,
  getFullName: function() {
    return this.firstName + " " + this.lastName;
  }
};

console.log("Full Name: " + person.getFullName());
console.log("Age: " + person.age);

This code creates an object person with four properties: firstName, lastName, age, and getFullName. The getFullName property is a function that returns the full name of the person. The last two lines of the code log the full name and age of the person to the console.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply