Predict the output of the following javascript code

+true;
!'Lydia';

 

 

 

 

  1. +true;

    The unary plus operator + tries to convert its operand to a number. In JavaScript, true evaluates to 1 when converted to a number, and false evaluates to 0. So, +true evaluates to 1.

  2. !'Lydia';

    The ! operator is the logical NOT operator. It converts its operand to a boolean value and then negates it. In JavaScript, any non-empty string evaluates to true when converted to a boolean, so 'Lydia' is initially true. The ! operator negates this, so !'Lydia' evaluates to false.

So, the evaluation of these expressions would be:

  1. +true evaluates to 1.

  2. !'Lydia' evaluates to false.