How to create javascript promise chain with array function?

I am facing a weired issue when creating a js promise chain.In promise,when I am using array function with (),I don’nt get the expected value.It give me the ‘undefined’ value in second then.

Here is the js code:

let x = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('sonet970@gmail.com');
    }, 2000);
});

function y(email) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(email);
        }, 4000);
    });
}

x.then((res) => {
    y(res);
})
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.log(err);
    });

But when I didn’t use the ()=>{} syntax inside the .then,I got the expected answer.

Here is the example of wright code:

let x = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('sonet970@gmail.com');
    }, 2000);
});

function y(email) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(email);
        }, 4000);
    });
}

x.then((res) => y(res))
    .then((res) => console.log(res))
    .catch((err) => console.log(err));

Can anyone please help me with this issu?
Thanks for advanced.

2 thoughts on “How to create javascript promise chain with array function?”