Daily JavaScript Quiz - 2024-04-23

  • Home /
  • Daily JavaScript Quiz - 2024-04-23

Daily Quiz - 2024-04-23

+true;
!'Lydia';

1 and false

false and NaN

false and false

true and true

The answer is Option 1

Sure! Let’s evaluate these expressions:

  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.

Javascript Quizzes