Use an IIFE to Create a Module part what I cannot delete the return keywords under ()=>{} function paradigm

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

let funModule = (
() => 
  {return { 
    isCuteMixin: (obj)=>{
      obj.isCute=()=>{true;};},
    singMixin: (obj)=>{
      obj.sing=()=>{console.log("Singing to an awesome tune");}}
  };})();

but the time I delete the return in the outer scope, this function will occur an error.
I mean that below code I showed is almost the same.

() => {return obj;}
() => obj;

so, why cannot delete the return keywords?

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15

Challenge: Use an IIFE to Create a Module

Link to the challenge:

You can delete the return, and those {} around the function body… But then you’re returning an object literal {} - which the fat arrow sees as a function body again!

But, if you wrap the returned object in parentheses: ({ }), then Javascript treats it as a returned object, and not the function body. :wink:

1 Like

You can also check out the “Function body” and “Returning object literals” sections of the arrow functions MDN article.

2 Likes

yeeeees, you are right , thank you!

1 Like

Very well said. Whenever possible, the docs are the best authority.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.