view raw
Walfrat Walfrat - 7 months ago 34
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 :'valid==true';+searchQuery;

The good syntax is to mive the ';' in the string :'valid==true;'+searchQuery;

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.