Skip to content

Instantly share code, notes, and snippets.

@moisescastillo
Created July 19, 2020 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisescastillo/1f1c30a4755a99696f4dae81c56b69d9 to your computer and use it in GitHub Desktop.
Save moisescastillo/1f1c30a4755a99696f4dae81c56b69d9 to your computer and use it in GitHub Desktop.
JavaScript object basic
const person = {
name: {first:'Bob', last: 'Smith'},
age: 32,
gender: 'male',
interests: ['Music', 'Boxing'],
greeting: function() {
console.log(`Hi, I\'m ${this.name.first}`);
},
fullName: function() {
console.log(`${this.name.first} ${this.name.last}`);
}
}
person.greeting();
// -> "Hi, I'm Bob"
person.fullName();
// -> "Bob Smith"
console.log(person.age);
// -> 32
console.log(person.interests[1]);
// -> "Boxing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment