0

Can any body explain this portion (url ? "/" + url : "") in the following function:

 function sendAjaxRequest(httpMethod, callback, url) {
 $.ajax("/api/web" + (url ? "/" + url : ""), {
 type: httpMethod, success: callback
 });
 }

as I cann't understand how it interpreted by calling wrapper function and get the intended URL value,

kvantour
  • 25,269
  • 4
  • 47
  • 72
abdoh m
  • 13
  • 5
  • 1
    This is a ternary operator: `a ? b : c` which reads if `a` is true, then return `b` otherwise `c` – kvantour Dec 08 '18 at 16:48
  • 1
    Possible duplicate of [JavaScript ternary operator example with functions](https://stackoverflow.com/questions/10323829/javascript-ternary-operator-example-with-functions) – angry_gopher Dec 08 '18 at 18:58

1 Answers1

2

res = "/api/web" + (url ? "/" + url : "" is equal to the following:

if (url) // if url is not empty
{
    res =  "/api/web" + "/" + url;
}
else 
{
    res =  "/api/web" + ""
}
pouyan
  • 3,445
  • 4
  • 26
  • 44