sum

return

setTimeout

// send the response after 1 second

if

typeof

!

==

"number"

||

typeof

!

==

"number"

// testing input types

return

new

TypeError

"Inputs must be numbers"

+

1000

=

10

5

document

write

" 10 + 5: "

return

null

"foo"

// Invalid data and return another promise

// Won't be called because of the error

catch

// The catch handler is called instead, after another second

console

.error

// => Please provide two numbers to sum.