Javascript Quiz with Explanation #coding #quiz #basics

preview_player
Показать описание
Java script quiz series...
Рекомендации по теме
Комментарии
Автор

output is 2.

Here's why:

JavaScript interprets the subtraction operation '1' - -'1'.

1.The second operand, - -'1', is a bit unusual. The first - is a unary negation operator, and the second - is a subtraction operator.

2.The unary negation operator - tries to convert '1' to a number, so it becomes -1.

The subtraction operation then becomes '1' - (-1), which is equivalent to 1 + 1.

The result is 2, and console.log(2); will output 2 to the console.

ItsMyWay