If you work with integers, this is usually safe. However, some floating point arithmetic operations can be very strange. If you perform floating point operations on a number before using the module, even if the logical result is always an integer, you should use:
Math.floor(x) % 3 === 0
But if it is always an integer, for example:
var x = 52; if(x % 3 === 0) {
Then itβs wonderful. As for your second question, the identification operator === also safe to use between numbers. For instance:
function x(y) { return y === 7; } alert(x(7.0));
Works correctly.
source share