JS

WAYS TO ABORT JAVASCRIPT EXECUTION

(quick guide & examples)

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

RETURN UNDEFINED

01

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

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();