Tuesday, February 27, 2024

JavaScript labeled statements = goto?

useful or dangerous for readability of code? 

GOTO in disguise?

Labeled statement - JavaScript | MDN

Scott Robinson on X: "TIL in JavaScript you can assign labels to if-statements and then specify which one you want to break out of. Super helpful for long and highly nested conditionals https://t.co/tjyDvWBPoe" / X

In the late sixties, Edsger Dijkstra wrote an article about the use of the goto statement, highlighting how it encouraged the spread of a unstructured code style often hard to understand: the so called spaghetti code. The proposed measure was the removal of the goto statement from all high-level programming languages in favour of the use of structured control flow constructs like if/elsewhilerepeat, etc.

No comments: