Some help please (JS) [Spoiler] NEW

const test= (function(){
  return function test (number, value=1){
    return number+value


So, what I think is going on here is that const test is made up of a function. The job of the function is to increment the number by the value that is passed in. If no value (just a number) is passed in, then the computer will automatically increment the number by 1 (num++). Then, if there is a value passed in along with the number, then the value will be added to the number, and then appear in my console. So, why are there those () at the end of the curly braces? I also don’t understand why the function is surrounded by brackets (or parentheses, depending on where you’re from, but that’s aside from the point).

An explanation would be great :slight_smile:

you have an anonymous immediately invoked function that returns an other function, I don’t know why it is there, but it is what it is

so you have
const test = (function () {return <a function>})()

this function is anonymous, I don’t know why you have it there, it is invoked there with the () just after it, it returns a function that is stored in the test variable

this other function that is returned is
function test (number, value=1){ return number+value }

the value=1 thing is a default parameter, if there is no value to assign to value, it takes the default value of 1

So the () triggers the second function to occur?

it makes the outer function execute immediately
this is called IIFE immediately Invoked Function Expression, if you want to research about it