I am fundamentally confused about something in my code.
If I code this on one of my .php pages:
$userEmail = $_SESSION["inputEmail"];
and then use it in an AJAX call inside one of my Javascript functions:
function firstFunction() {
    $.ajax({
        url: someUrl.php?inputEmail='<?php echo $userEmail ?'>
        sync: true,
        success: function(result) {
          $("#someDiv").html(result)
         }
      })
}
I end up getting the result I need. I am confused, however, because if in this function, I did something like this:
function secondFunction() {
    if (<?php echo $userEmail ?> == "test@test.com") {
        //do some stuff
    }
}
It does not work. I have read answers to this exact scenario right above, but I don't understand why the first line of code I provided in this example works but this second one does not.
Initially, I expected the Javascript to be able to read $userEmail in the function above, but after viewing the page source, I see it is evaluation nothing. It looks like:
if(  == "test@test.com)
Like I said, I've looked this part up. But now I'm even more confused. Why can I do the AJAX call under firstFunction() but not secondFunction()
 
    