How do I use the modulus operator?

When using the % operator I am left with the error “Did you forget a , here?”. Is there another keyword for % in ReScript?

Js.log(20 % 2) 

Note: This is a translation of this question for ReasonML.

The modulo operator is a plain function called mod in ReScript. It can be used either with or without a pipe:

let x = 20->mod(2)
let y = mod(20, 2)

It’s documented in the language overview, comparing JavaScript constructs with their equivalent in ReScript.

Leave a Comment