Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 8, 2023 14:57
Show Gist options
  • Save suhailgupta03/cdbf1a98d765ef5d381da3941c54aabf to your computer and use it in GitHub Desktop.
Save suhailgupta03/cdbf1a98d765ef5d381da3941c54aabf to your computer and use it in GitHub Desktop.
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