I have something like the following:
var val = "string";
var testVal = val && val.length;
&& operator doesn't perform a type casting. The expression it forms is just evaluated to the left-hand operand if this operand is falsy, otherwise to the right-hand operand.
You have to explicitly convert to boolean:
var testVal = !!(val && val.length);