I'm working on a JS mod for Shopify. I have been told that Liquid renders first, then JS.
With that in mind, I'm a bit confused as to how to implement a piece of logic.
I want to check if the customer object is present (logged in) and if so I want to set a JS variable customerID to the value of the customer's ID attribute.
Currently, I'm working with
{% if customer %}
<script>
var sasCustomerId = {{ customer.id }};
</script>
{% endif %}
What I don't understand is how this can render properly. If the Liquid goes first, that would leave
{% if customer %}
{{ customer.id }}
{% endif %}
Which seems strange. Is this an instantaneous thing where it happens "first" but is instantaneous from the user's point of view?
Sorry if this is a dumb question. Not a Compsci guy myself though I'd love to learn more about how all these scripts I write actually work if anyone would care to educate me.
Thanks!