Why does the string in JavaScript change from Jabberwocky to NaN?

  node.js, question

图片描述
As the function shown in the figure, three strings are passed in, and the other two are stored in the database without any problem. Only brief will somehow become NaN. What is the possible reason?

Incoming parameters:
图片描述

Spliced query string:
图片描述

As shown in the picture, what should have been “this brief” has become NaN.

If you accidentally write an expression like (plus’ abc’).
Js here will understand the plus sign as a unary operator that “does not change the sign” instead of the “string join” Binary operation you want.
So here js will implicitly help you convert’ ABC’ into a numeric type, which is NaN.
From the screenshot, it is obvious that you wrote an extra plus sign to cause this problem.
The reason why the above items are not problematic is that the above items are originally of numeric type, so multiple plus signs are not harmful. However, this also reminds you that it is better to be neat when splicing strings, or consider using some template method to prevent accidental writing errors. At the same time, your SQL is spelled out without parameterization, and there is also the potential risk of SQL injection.