无法将php变量传递给javascript

I am trying to pass a php variable to Javascript that hold the name of the table, data will be written in. However I can not see the value when I console.log it. The script is activate on click, so it should not be an issue with page load, but I am not very good with javascript, so I have no idea what I am doing wrong

Could someone help me out?

global $user;
            $user = user_load($user->uid);

            $params = Array (   
                                'company'   =>  $user->field_active_company[LANGUAGE_NONE][0]['value'] ,
                            );
$id = $user->name;          
$cu = "db_".$params['company'];
//Here I can see the value fine
echo $cu; 

.
.
.
.
//here I can not.
 var write = '<?php echo json_encode($cu); ?>';
 console.log(write);
var write2 = '<?php echo $cu; ?>';
console.log(write2);

Thanks for helping

EDIT: to clarify 1ST I am asking why it does not work (or how to fix it). 2ND Like I mention in the text the javascript has a function around it and all the needed tags. I am console logging textboxes prior to the javascript/php part.

console.log() doesn't print anything if the value is undefined. So maybe php is not rendering the value, or if the value is a string it's lacking double quotes "". You can see what is rendering php in the browser html code. Hope it is just double quotes.

Still do not know what the issue was. I ended up passing the value trough hidden field. This solved my issue, but could not find answer to my question. Daniel was right about the the value not coming trough.

Offtopic: BTW. what is up with stackoverflow now a days. People will get mad if their solution did not work, down vote everything and mark dublicates without reading the question properly. The site has really become terrible from what it was few years back...