Passing an Arduino Variable to JS

This may be a very simple question for someone out there.

Say I have an int Arduino vairble:

int sensorData = analogRead(sensorPin);

How would I be able to pass that as a JS variable?

client.println("<script> var dat = sensorData </script>"); // this is what I have tried

For more context, I am trying to pass the variable to update a webpage heading; which does work if I pass in a JS variable, but not an Arduino one:

client.println("<h1 id="sensorData"> %SENSORDATA% </h1>");
client.println("document.getElementById("sensorData").innerHTML = dat");

Any help would be greatly appreciated.