Created
August 8, 2023 14:57
-
-
Save suhailgupta03/cdbf1a98d765ef5d381da3941c54aabf to your computer and use it in GitHub Desktop.
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
| function Dog() { | |
| const name = "Buzo"; | |
| const age = 3; | |
| const color = "black"; | |
| const sound = "woof"; | |
| function bark() { | |
| console.log(sound); | |
| } | |
| function getAge() { | |
| console.log(age); | |
| } | |
| function getColor() { | |
| return color; | |
| } | |
| return { | |
| bark: bark, | |
| getAge: getAge, | |
| getColor: getColor | |
| } // this is an object | |
| // which has bark, getAge, getColor as properties | |
| } | |
| const myDog = Dog(); // myDog is an object, because the call to Dog() | |
| // returns an object | |
| myDog.bark(); // woof | |
| myDog.getAge(); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment