Does division in JavaScript work like regular division or is it integer division like in some other languages?


#1

Question

Does division in JavaScript work like regular division or is it integer division like in some other languages?

Answer

JavaScript uses regular division as used in mathematics. So 3 / 2 gives you 1.5 instead of 1 like with integer division. If you do want to use integer division you’d have to round down the result like so: Math.floor(3 / 2).