Let's break down Javascript concepts:
1. Evaluating console.log(+true);
- Unary Plus Operator (
+): This operator attempts to convert its operand into a number. - Operand:
true: In JavaScript, the boolean valuetrueis converted to the number1when using the unary plus operator.
NOTE : true → 1 & false → 0.
Evaluation:
+true→1- Output:
- The
console.logfunction prints1to the console.
2. Evaluating console.log(!"ValueAdda");
- Logical NOT Operator (
!): This operator inverts the boolean value of its operand. If the operand is truthy,!converts it tofalse; if falsy, totrue. - Operand:
"ValueAdda": In JavaScript, non-empty strings are considered truthy values.
NOTE : falsy values in javascript are "", 0, false, null, undefined, NaN, and 0n. Here NaN means not a number and it's type if number and 0n mean representation of 0 in BigInt number.
- Evaluation:
!"ValueAdda"→false- Output:
- The
console.logfunction printsfalseto the console.
Summary of Outputs:
- The first
console.logoutputs1. - The second
console.logoutputsfalse.
Understanding these operators and their behavior with different data types is crucial for effective JavaScript programming.
Answer is : A) 1 false
