Skip to main content
1 of 5
corvus_192
  • 5.7k
  • 15
  • 24

Javscript (node), 27 bytes, 2 exit codes

Full program:

if(+process.argv[2])throw 1

Function:

f=i=>i&&f(i)

process.argv is an array that contains the path to the node executable, the path to the javascript file executed and the command line arguments. In this case, this will be either "1" or "0". The string is converted to a number with the unary + operator. if the number is truthy (not zero), an error is thrown and the program exists with exit code 1.

The function expects the input as a number. If the input is truthy, the function calls itself, and crashes the node runtime with a stack overflow. If the input is 0, the lazy && operator returns 0 without evaluating the right hand side.

corvus_192
  • 5.7k
  • 15
  • 24