Set Default Parameters for Your Functions - help understanding

Hey all - so I passed this test easy… just by following directions… just add 1 in the right place…

However, I do not understand the problem as whole… this does not look like a function I am use to seeing and working with on FCC… can someone please help me understand this ???

What I see is: const obj that is equal to a function, why is the function encased in () and have () at the ending??? it super confusing…

const obj = (function(){}) () why is there a () at the end? and why is it incased??? I want to fully undestand how this function is working, and sucks the FCC doesnt really explain it…

ANY HELP would be great!

When you ask a question please provide the challenge link, otherwise we don’t have any idea about what you are talking

just added it! Thanks for letting me know!!

const increment = (function () {})();
First, const increment is just a variable being declared, there is no object here (well, functions are objects, but that is an other topic)

function () {} is just a normal function, it returns a function (that is a thing, yes! It is not different from storing directly a function in a variable).

The fact that it has () at the end, means it is invoked immediately (remember that you write the function name plus () to call the function), and that makes this a Immediately Invoked Function Expression, or IIFE.

Why do we need a IIFE here?
It is a thing for the tests, as for activating the strict mode there is need of a scope, a closed environment and the IIFE create it.

Why do we need strict mode?
We actually don’t need this anymore, but it seems the challenge has not yet been changed from when it was needed, it made so that some silent errors would be handled with actual messages, instead of just not working - much easier for debugging.

1 Like

thank you !!! I understand it a lot more then before… but I still need to really dig in deep… thank you for your explanation!

You have every right to be confused. The IIFEs were in my opinion very willy-nilly introduced into challenges.

Throwing code like this…

const increment = (function() {
  "use strict";
  return function increment(number, value) {
    return number + value;

…at the camper when teaching something as simple as default function parameters is just silly. But as said they have been removed and we “just” need the site updated.