Skip to content

IV Javascript

Sandesh Kota edited this page Dec 5, 2019 · 23 revisions
  • Output ?
const timerId = setTimeout (
    () => console.log('No wati time'),
    0
);
clearTimeout(timerId);
setTimeout(
  () => console.log('Hello after 0.5 seconds!'),
  500
);

for(let i = 0; i < 1e10; i++) {
  // Some logic
}
  • Call a function every 2 second. Retry it only for 5 times

let i =0;
const timerId = setInterval (
    () => {
        i++;
        if(i == 5){
            console.log('clearing after 5 retries');
            clearInterval(timerId);
        }
        var result = LoadData();
        console.log(result);
        if(result == 'success'){
            console.log('clearing since it is a success');
            clearInterval(timerId);
        }
    },
    500
);


const LoadData = () => {
    // ajax call
    return 'failure';
}

Clone this wiki locally