(Not So) Fun with Filters
I saw this recently on a thread in the Shopify Partner's Slack.
A developer was confused by why the same math formula was returning different results when written in JS vs Liquid
// JS returns 1567.5
1600 - 130 / 4
// Liquid returns 367
1600 | minus: 130 | divided_by: 4
Do you see what's going on here?
It turns out that order of operation rules in Liquid filters don't behave as you'd necessarily expect. Mathematically those two lines are equivalent to this
// JS returns 1567.5
1600 - (130 / 4)
// Liquid returns 367
(1600 - 130) / 4
Thanks to Liam Merlyn, Dan Gamble and Antti Sirviö for the interesting example