if my JS code like
age = new Date().getFullYear()-getYearInteger();
In order to save JS value to a PHP variable you need to make a server call.
You can easily do the vice versa though like this:
var jsVariable = '<?= $php_variable ?>';
Have an ajax call, send the data to server side and store in variable.