nested callbacks javascript code example

Example: nested callbacks javascript

//nested callback eg, with conditional check for url

function download3(urls, success, fail) {
            setTimeout(() => {
                console.log(`Downloading ${urls} ...`);
                var err = urls.length === 0 || !urls;
                err ? fail(urls) : success(urls);
            }, 3000);
        }

        const url_a = 'https://www.javascripttutorial.net/pic1.jpg';
        const url_b = 'https://www.javascripttutorial.net/pic2.jpg';
        const url_c = '';

        download3(url_a, function(picture_a) {
            console.log(`Processing ${picture_a}`);

              download3(url_b, function(picture_b) {
                  console.log(`Processing ${picture_b}`);

                    download3(url_c, function(picture_c) {
                        console.log(`Processing ${picture_c}`);
                    }, function(picture_a){
                        console.log(`Handling error...`)});

              },function(picture_b){
                      console.log(`Handling error...`)});

        },function(picture_c){
                    console.log(`Handling error...`)});