Quiz Explanation
+true;
The unary plus operator
+
tries to convert its operand to a number. In JavaScript,true
evaluates to1
when converted to a number, andfalse
evaluates to0
. So,+true
evaluates to1
.!'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 totrue
when converted to a boolean, so'Lydia'
is initiallytrue
. The!
operator negates this, so!'Lydia'
evaluates tofalse
.
So, the evaluation of these expressions would be:
+true
evaluates to1
.!'Lydia'
evaluates tofalse
.