Walfrat Walfrat - 14 days ago 5x
Javascript Question

How can '+myVar;' be a valid syntax

I just got a bug that took some of my time to spot my searching filters weren't working because of the following code :


The good syntax is to mive the ';' in the string :


The reasn why i didn't spot that is because the earlier line of code didn't triggered any javascript console error. So it seems it's a valid syntax.

So here is my question, how can this be a valid syntax ?


+something is an expression using the plus unary operator.

Its general purpose is to convert a value, for example a string, to a number.