const test= (function(){
return function test (number, value=1){
return number+value
}
})()
console.log(test(5))
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