the cookie will not be accessible before script termination, so I don't think javascript will see it if the js code is produced by the same script.
but in order to work around that problem,
the php can hard code the cookie information into the javascript that php produces.
<?
... php does setcookie(... $thecookievalue) ...
... start html (including js) output ...
?>
...
<head>
<script>
if(document.cookie == '')
var thecookievalue = '<?=$thecookivalue ?>';
else
var thecookievalue = document.cookie;
... further js processing ...
</script>
...
I hope you got the principle.