Skip to content

Instantly share code, notes, and snippets.

@toshvelaga
Created October 24, 2021 02:13
Show Gist options
  • Select an option

  • Save toshvelaga/c7821a58cdde19fe057f072d5a0183dd to your computer and use it in GitHub Desktop.

Select an option

Save toshvelaga/c7821a58cdde19fe057f072d5a0183dd to your computer and use it in GitHub Desktop.
Examples of how to create an object in Javascript
let beer = { name: 'Hopadillo', ABV: '6.6%', price: '$2.00' }
// OR
let beer = new Object({ name: 'Hopadillo', ABV: '6.6%', price: '$2.00' })
// OR
function alcohol(name, ABV, price){
this.name = name;
this.ABV = ABV;
this.price = price;
}
let beer = new alcohol('Hopadillo', 'red', '6.6%', '$2.00')
// OR
class Alcohol {
constructor(name, ABV, price) {
this.name = name;
this.maker = maker;
this.engine = engine;
}
}
let beer = new Alcohol('Hopadillo', '6.6%', '$2.00');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment