We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Ethan • 3 years ago

Wow, I love the "Your first code with promises" page. This has actually helped me a lot as I was actually recently thinking of delving into promises and that stuff. Tech.io is really as good as they say it is!

GrennKren • 1 year ago

hmm.. I cant solve practice in #9.
The output was
Testing with data test (string)
Testing with data 3 (number)
Testing with data 6 (number)
Promise is resolved but it should be rejected

but basically I've already using isNaN function to determine if is not a number.
if(isNaN(data) === false){
doing check if data is even or odd, then use settimeout
call function from second parameter which use for handle error

Ashwatthama • 1 year ago

I struggled on that one too. But found out that we need to reject the promise if the number is even or not a number! Question was simple though!

return new Promise((resolve, reject) => {
} else if(data%2 === 0) {
setTimeout(reject, 2000, 'even');
} else {
setTimeout(resolve, 1000, 'odd');


GrennKren • 1 year ago

forget it, I didnt notice the rules.. the odd should be return as rejected

kaos2oak • 3 years ago

I guess we all know what green and red indicate, but for a first-time user on the first click of the button, there is a lingering question of "does the button turning green mean I got it right, or am I still waiting for something more to happen". Might be nice if the text of the button changed, too. "Got it!" or "Try again" might be appropriate.

kaos2oak • 3 years ago

Typo: "Some pratice" should be "Some practice"

Magus • 3 years ago

Fixed. Thanks. As well as others typos.

Jason Lukose • 3 years ago

The code sections should be expandable.

Jerome Cance • 3 years ago

What do you mean by expandable? Normally the code section is big enough to contain the whole code. If not, what's your browser?

Anonymous • 3 years ago

It seems like it was a bug yesterday. I contacted the tech.io helpdesk and they said they have fixed it now. :)

kaos2oak • 3 years ago

"In the future, synchronous http requests will be not supported by browsers"
should be
"In the future, synchronous http requests will not be supported by browsers"

Anonymous • 5 months ago

Hi all!
Is the answer for practise #4 the following?

function job(callback1, callback2) {
setTimeout(callback1, 2000);

setInterval(callback2, 1000);
setInterval(callback2, 1000);
setInterval(callback2, 1000);



module.exports = job;

Sarah Bao • 8 months ago

function job(callback1, callback2) {


let counter = 1;

var timer=setInterval(function(){


module.exports = job;

paszo • 8 months ago

Typo in the 14/17 second example.
is: cconsole.log(data);
should be: console.log(data);

shyamkondisetty • 11 months ago


this.bankClient.checkDetails(payment.beneficiary).then((_beneficiaryResult) => {
this.bankClient.checkDetails(payment.payee).then((_payeeResult) => {
this.fraudManagementClient.checkFraud(payment).then(async (_fraudResult) => {
await this.bankDetails.save(payment.beneficiary);
await this.bankDetails.save(payment.payee);
let savedPayment = await this.payments.save(payment)
return resolve(savedPayment);
}).catch((_error) => {
return reject(new BankAccountDetailsNotFound(payment.payee.name + "'s bank account details are invalid"))
}).catch((_error) => {
return reject(new BankAccountDetailsNotFound(payment.beneficiary.name + "'s bank account details are invalid"))

Agata • 1 year ago

I'm having trouble understanding the third question of the quiz on page 13/17. When we get to this

.then(function(data) {

return new Error('test');

why does it continue to the next .then statement instead of to the next .catch? Thanks!

mohammed • 9 months ago

By default using just new Error("error") won't throw any error from the program..instead it will continue to the next line.
if you wanted to bring your error into catch block then you need to do something like throw new Error("error")'; (now you will notice it will trigger catch block instead of then block)

.then(function(data) {

throw new Error('test');

Man Saha • 1 year ago

So, to not broke the chain, we could also write it like this

function test() {
const promise = job();
const result = promise.then(function(data) {
doSomething(data); // whether doSomething() returns a promise (async) or not (sync), in this example it depends on the data, so this example literally tells us that doSomething() must happen after job()
return result;

Sunil Kumar Yadav • 1 year ago

const checkNumberPromise = (data)=> new Promise(
(resolve, reject)=>{
} else if(data % 2 !== 0) {
resolve("odd", 1000)
} else {
reject("even", 2000)
}, 2000)

Fezekile Plaatyi • 1 year ago

Thanks a lot, it easy to follow it

Anton Bagdatyev • 1 year ago

I guess explanation of Line 10 is wrong or at least it's misleading.

>> When you are in a then callback, if you return a promise, it will be the resulting promise of the then call. <<<

".then(onResolvedCallback)" always returns a promise in the current run of the JS event loop, but this returned promise is not the one you return in "onResolvedCallback" (which runs after at the end of the current run of the JS event loop).

I think the explanation should be:
> When you are in a "then" callback, if you return a promise you will cause the promise returned by the "then" call to wait until the returned promise in the callback resolves too before resolving that promise returned by "then".

Avigo Development • 1 year ago

Great article!
I would recommend you my small library https://www.npmjs.com/packa...
Used to execute all the promises whether they resolve or reject
Check examples from README (or test files)
Can be used in Browser/NodeJS

Ayush Jain • 1 year ago

Forund this over web:

ursusfelis • 3 years ago

Excelent, very simple to understand

chiposaur • 3 years ago

On "The challenges of the asynchronous" page it says:

> "If job1 is a framejob function, you can't modify it."

What is a "framejob" function?

This was great up to this point. The assumption of basic JS knowledge is a good baseline, fine. However, this is a phrase I've never heard, google returns no definitions.

Magus • 3 years ago

framejob refers to a given function that you must call but you can't modify it. But i agree this word should not be here. I'll try to rephrase this one.

[CG]Nonofr • 3 years ago

Typo in `Traps of promises`: `Promise.resvole` => `Promise.resolve`

kaos2oak • 3 years ago

Typos (2):
"Your code will be actually faster because you can perform other tass while waiting for an asynchronous function to finish running"
should be
"Your code will actually be faster because you can perform other tasks while waiting for an asynchronous function to finish running"

jdyerjdyer • 3 years ago

Javascript promises, mastering the asynchronous - The Challenges - Downside Examples (Side note, shouldn't these discussions be per page, not per topic??)

I understand the concept, but a concrete example could make this clearer to the beginning programmer, especially one who hasn't had to handle these types of synchronous actions in an asynchronous environment before.

jdyerjdyer • 3 years ago

A good example could be an abstract email service provider task:
Job1 could be contactList = getContactList("AwesomeWebsiteContacts"),
Job2 could be Thornton = getContactEmail(contactList, "BillyBob"),
Job3 could be sendEmail(Thornton, "Thanks for Subscribing!" "You are awesome for subscribing to my Awesome Website!")