PHP to set JS variable outside of JS file

All my JavaScript is usually unobtrusive, however I need PHP to set a simple JavaScript value:


the_value = 1;

(it has to be set by PHP depending on some calculations)

How is the best way to do this as I don;t like the below method?


<script>
the_value = "<?php echo $the_value; ?>";
</script>

I have heard of setting the value in a hidden text field, but I like the idea of setting something like this:


<meta id="the_value" content="1">

…where I can then use the unobtrusive JS to grab the value.

Is that possible?

What is the best way to do this?

You can access the value with the expression:


var myVar = Number( document.getElementById( 'the_value' ).content );

Great. Thanks.

So is doing it with:


<meta id="the_value" content="1">

the best way to do it, or would there be a better way?

Thanks

What was the problem with just…

the_value = “<?php echo $the_value; ?>”;