0
<script>

    function my_function_for_good_response(response){
        console.log(response)
    }

    my_promise_function(1)
        .then((response) => console.log(response))
        .catch((response) => console.log(response))

    my_promise_function(0)
        .then(my_function_for_good_response())
        .catch((response) => console.log(response))

    function my_promise_function(parameter){

        return new Promise((resolve, reject) => {

            if (parameter>0){
                console.log()
                resolve("good response")
            }else{
                reject('bad response')
            }
        })
    }

</script>

//console:
undefined
good response
bad response

why is ' undefined' printed?if in the second case the response is of reject type

why is 'undefined' printed in the first line?should it be in the second line?

and why doesn't 'my_function_for_good_response' work if it is absolutely the same as the arrow function?

Giovanni5454
  • 33
  • 1
  • 6
  • 1
    You're calling your function, you need to let JS call it for you by just passing the reference to it `.then(my_function_for_good_response)` – Nick Parsons Oct 22 '22 at 10:53
  • 2
    @NickParsons thanks, until now I thought that if I write my_function() as an argument to another function, it will be considered to be a function, but now I realize that it is the result of it. – Giovanni5454 Oct 22 '22 at 10:58

0 Answers0