JavaScript Handling Errors

Rebecca Palumbo
Rebecca Palumbo
5,505 Points

How is it that you can call a function into a then handler without an argument or parentheses?

But then you put an argument in the function? I'm confused. I'm referring to the checkStatus function here.

2 Answers

Steven Parker
Steven Parker
187,600 Points

When you set up a handler, one of the arguments is a function. But you don't want to call the function at that point, you only want to pass a reference to the function so the handler can call it when the event occurs.

That's why when you use a named function as a callback argument you don't put parentheses after the name.

Steven Parker
Steven Parker
187,600 Points

A "then" always passes the fulfillment value (that it gets from the promise it is attached to) along to handler function. So even though you only give the function's name to "then", when the function is actually called, it gets an argument.

Rebecca Palumbo
Rebecca Palumbo
5,505 Points

I don't understand. At the end of the video, there is .then(checkStatus) which calls the checkStatus function that has a response argument. How does this work? The .then handler with the call for checkStatus doesn't have an argument. How does the response info get transferred to the function? Would any function have response info transferred with it?