Confused with brackects inside function

Confused with brackects inside function

const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
const half = (function() {
“use strict”; // do not change this line

// change code below this line
return function half(stats) {
// use function argument destructuring
return (stats.max + stats.min) / 2.0;
// change code above this line

console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

i dont understand what with all the brackets and curly braces from line “const half” and the third last line of code.
i understand that half is a const variable which contain function expression and this anonymous function calls other function half with argument as “stats”.

if i remove the inner code then it looks like:

const half = (function()
some code


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

Note: Backticks are not single quotes.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


That’s what’s known as an Immediately Invoked Function Expression or IIFE. There is some documentation here. They’re a useful tool but they can certainly seem strange at first. You didn’t provide a link to the problem so I don’t know where it is in the curriculum, but I’m sure you can find materials out there. I might suggest checking youtube too.


Please be sure not to ask the same question twice, I just deleted the other thread.


this is the problem

but i have seen many problems with this kind of code in fcc


IC. Yes, the IIFEs aren’t discussed until the Object Oriented section. There is a problem in some of the problems of using techniques not taught yet. It’s a volunteer operation - someone will get around to fixing it eventually.