You should consider doing this the other way around using Ajax. You get the Javascript side to send a request to a php script that will calculate everything and send back the desired data as a string. You can then use that string in Javascript without ever needing to print the value in your front end.
First send an Ajax request just before using the string.
Make sure you have the jQuery plugin and that this code is inside a jQuery document ready.
You can Embed a CDN of jQuery here
https://code.jquery.com/
$( document ).ready(function() {
$.Ajax('/ajax.php',
{
dataType: 'json', // type of response data
timeout: 500, // timeout milliseconds
success: function (data,status,xhr) { // success callback function
//Your string is inside data.responss
alert(data.responss+" is your value");
},
error: function (jqXhr, textStatus, errorMessage) { // error callback
$('p').append('Error: ' + errorMessage);
}
});
});
Then in your ajax.php file you echo the var in json format
<?php
// [...]
$data["responss"] = 2000;
echo json_encode($data);
?>
Your result will be inside data.responss and available inside the success {} You can create a fallout event if something goes wrong using the error portion or by testing if data.responss is what you are expecting.
Keep in mind that PHP is server side and Javascript is client side. PHP will always be executed first. So using Ajax, you can call the PHP result at the right time in your load. So sending something to Javascript (Client side) can't be done from the server side because it's already executed. You can print your Javascript from PHP but then you would have the value in clear text inside the body of your HTML.
Anyway, hope that makes sens to you. Let me know if you have problems implementing this.