JS

WAYS TO ABORT JAVASCRIPT EXECUTION

function demo () {   DO PROCESSING   var foo = "BAR";   RETURN FALSE OR UNDEFINED   return ;   THIS WILL NOT RUN   foo = "ZOO"; }

RETURN UNDEFINED

01

function demo () {   DO PROCESSING   var foo = "BAR";   THROW ERROR   throw new Error ("STOP");   THIS WILL NOT RUN   foo = "ZOO"; }

THROW AN ERROR

02

FUNCTION TO LOOP var demo = () => { var foo = "BAR"; };

TIMER STOP

03

START INTERVAL TIMER var timer = setInterval(demo, 1000);

STOP RUNNING clearInterval(timer);

CREATE WORKER var theWorker = new Worker ('SCRIPT.JS');   STOP WORKER theWorker.terminate();

JAVASCRIPT WORKER

04

STOP ENTIRE WINDOW FROM LOADING. NOT VERY USEFUL, BUT GOOD FOR "EMERGENCY BREAK". window.stop();

WINDOW STOP

05

IMMEDIATE STOP (ABRUPT) process.abort();

NODEJS ABORT

06

GRACEFUL STOP process.exit();