I have the following code that passes a variable (EmployeeID) from PHP into JavaScript:
EmployeeID= <?php echo "$EmployeeID"?>;
The issue is that the variable EmployeeID in PHP might not exist, in which case, after I run the JavaScript code, I receive an error
Uncaught SyntaxError: Unexpected token
When I look into the Source Code in Dev Tools I can see this:
EmployeeID = ;
What would be the best way to handle this error? I tried
if (EmployeeID == null){
EmployeeID = "0"; //0 - stands for generic variable in case if EmployeeID doesn't exist
}
Any help would be greatly appreciated!