Javascript 😩😩 #javascript #js #meme #programming

preview_player
Показать описание
In JavaScript, the "+" operator is overloaded to serve as both a mathematical addition operator as well as a string concatenation operator. So, when one of the operands is a string, the operator performs string concatenation. This is why "5" + 2 evaluates to "52" instead of 7.

On the other hand, the "-" operator only serves as a mathematical subtraction operator. So, when both operands are numbers, it performs mathematical subtraction. This is why "5" - 2 evaluates to 3.

It's important to keep this behavior in mind when using JavaScript, especially when working with strings and numbers in the same expression. It's always a good practice to explicitly convert the operands to the desired type (e.g. using Number("5") instead of "5") to avoid unexpected results.
Рекомендации по теме
Комментарии
Автор

Str + 3 here it treat 3 as an str and concatenate it

SumanSingh-pmxe