What is the purpose of the open parenthesis on the callback?

I have these two functions that work as expected:

//Fibonacci sequencer
const add_it = (number, previous, alist, nth, start) => {
    console.log(" *************  ")
    let next_number = previous + number;
    let next_start = start + 1
    if(next_start >= nth){
      console.log("-----------    final list  ------------")
    else {
      add_it(next_number, number, alist, nth, next_start);
//simple print the next number

const LineLog_count = ((c, max_num) => { //<-- the open parenthesis
    let x = c + 1
    if(max_num > x) {
      message = "repeating linelog :"
      console.log(message, x)
      LineLog_count(x, max_num) }
    else {
      let message = "done :::>>"
      console.log(message, x, max_num)

My question is, What purpose does that open parenthesis have?

1 Like

That’s a self executing anonymous function. It is self invoking. You don’t need to give it a name and call it later.
But this is advanced stuff, why did you start with it? It’s a bit mind warping. Take it slow , gradually from the simple stuff to the more difficult.
Look at ex11 in LJSTHW, Zed talks about anonymous functions and gives an example of one in a callback. Have you seen that video? He explains exactly that, watching it now :wink: (minute 18:36 on)

1 Like

@nellietobey, @io_io I think this stuff is equivalent to a (anonymous) lambda function in Python.


Yes, I thought about it too when I learned about lambda functions. They resemble very much.

1 Like

Oh man, I totally saw this and I think I used it but my brain is drawing a blank. Did you see it up somewhere and they didn’t explain it?


I was trying to make callbacks, see how they work, and I’m pretty sure I had the idea all wrong. You explain it in the video, I just didn’t pay enough attention the first time around.


1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.