JSLint complaints when calculating squares, as in * a

When I write this Javascript code:

var a = 2; var aSquared = a * a; 

JSLint marks a * a as a weird destination. It refers only to the product, not the destination (I am using Netbeans 7.3).

I know that I can use Math.pow(a, 2) , but such a calculation is performed in a dense iterative numerical calculation and the difference matters .

Is it really weird to calculate the squares this way?

+4
source share
1 answer

Personally, I would just ignore it - this is just a warning, and you know that the code is good, so ... meh.

But if you really want to avoid the warning, you can try wrapping a few brackets around it:

 var aSquared = (a * a); 

Or you can replace your code with something like this:

 function squared(a) { return a *= a; } 
+2
source

All Articles