Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

function as object

// Function declaration.
function showFavoriteIceCream() {
  const favIceCream = 'chocolate';

  console.log(`My favorite ice cream is ${favIceCream}`);
}

// Let's assign a property.
showFavoriteIceCream.flavours = ['chocolate', 'vanilla', 'strawberry'];

// Let's log the showFavoriteIceCream function.
console.log(showFavoriteIceCream);

// Log
// { [Function: showFavoriteIceCream]
// flavours: [ 'chocolate', 'vanilla', 'strawberry' ] } -> property assigned
Source by academind.com #
 
PREVIOUS NEXT
Tagged: #function #object
ADD COMMENT
Topic
Name
5+7 =