Created
October 24, 2021 02:13
-
-
Save toshvelaga/c7821a58cdde19fe057f072d5a0183dd to your computer and use it in GitHub Desktop.
Examples of how to create an object in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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