/ Handling undefined

Bugs due to undefined vars are one of the most annoying things about JS: code thought to be working suddenly starts throwing errors.

Below are some of the things you can do to minimise this in Jsi.

Strict Mode

To reduce coding errors and enable maximal checking, use strict mode by starting with:

"use strict";


#!/usr/bin/env jsish
"use strict";


Expression checking should be as simple as possible, eg:

if (x) ...

is often preferred to:

if (x != '') ...
if (x != 0) ...

because it handles the case where x may be undefined.


Jsi will check for undefined vars used on the left-hand side (LHS) of conditional expressions. To such avoid errors, put the var on the RHS.

"use strict";
var x;
if ('' === x) puts('x empty'); //OK.
if (x === '') puts('x empty');
/tmp/us.jsi:4: error: lhs value undefined in ===/!==