Can anybody explain me this behaviour with JS?

I ran this in my Node REPL


Hi @Sourabh_Shukla and welcome to the community :wave:

The plus sign is not just used to add numbers, but also as a so called unary plus (+) operator. When used with a number it just returns the same number, but when used with something else it first tries to convert the value to a number. Since the string in your example only contains a number this conversions succeeds.

It’s the simplest and fastest method when you need to convert a number string to an actual number.

Have a nice day,