Variable problem: Unexpected identifier

This is my code:
function show_btn(){
    var actualproject2 = new String('String');
    actualproject2 = <?php echo $_SESSION["actualproject"]; ?> ;
$.ajax({
  method:"POST",
  url: '/wp-content/themes/ne4/PJson.php',
  data:  {
    "getCanvas":1,
    "whichProject":actualproject2,
    },
    datatype: "text",
    success: function(strdate){
   console.log(strdate);
     }
 });
}

Open in new window


Uncaught SyntaxError: Unexpected identifier

In debugger I may see:
function show_btn(){
    var actualproject2 = new String('String');
    actualproject2 = First project;

Open in new window


I think the problem is blank space between "First" and "project", because it is also  underlined with red in debugger.
What correction must I perform to resolve this problem?
(i did try to solve it with:     var actualproject2 = new String('String');, but no success)
Ivan GolubarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
If you are trying to assing "First project" to the string actualproject2 that you are creating, then:

function show_btn(){
    var actualproject2 = new String('First project');
}

Open in new window


»bp
0
Ivan GolubarAuthor Commented:
actualproject2 = <?php echo $_SESSION["actualproject"]; ?> ;

Open in new window


But debugger sees it as:  actualproject2 = First project;

Check attached image.
string.png
0
Olaf DoschkeSoftware DeveloperCommented:
Yes, you need to put that into quotes:

actualproject2 = "<?php echo $_SESSION["actualproject"]; ?>";

Open in new window


Bye, Olaf.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.