Need help in interpreting a specific strict equality syntax

I ran into the following line of code found online from a Google search. It is related to a project I am starting to solidify my JavaScript knowledge gained from the Codecademy “Learn JavaScript” course. Would someone be able to explain how I should interpret the syntax on the right side of the strict equality in the line of code below? I have looked everywhere without any success. :frowning_face:

const var2 = var1 === 0 ? '?' : '&';

Without copying in the entire code block for context, I can say that var1 is expected to be a number. More specifically, it is a page index into a PayPal transaction download that can span multiple pages. (The project I am working on is to use the PayPal API to download account transactions to a Google Sheet.)

Note that what I am looking at online is a Google Apps Script, which by definition is built on JavaScript. However, I assume this line of code is purely JavaScript.


You could understand it as:

const var2 = ( (var1 === 0) ? '?' : '&' )

To the right of the assignment operator    =   , a ternary operator is being used.
(see Conditional (ternary) operator - JavaScript | MDN)

It basically evaluates the expression to the left of the ternary operator    ?   
If the expression (condition) evaluates to true (truthy), then the expression before the    :    will be executed.
If the expression (condition) evaluates to false (falsy), then the expression after the    :    will be executed.

In your example, if var1 is 0, then the string '?' will be assigned to var2. If var1 is not 0, then the string '&' will be assigned to var2.
You can think of it as:

var1 = // holds some value from somewhere earlier in code

let result;

if (var1 === 0) {
    result = '?'
} else {
    result = '&'

const var2 = result;

I suspect the '? and '&' characters are being used to construct a query string (see Query string - Wikipedia)

Thanks MtRtMk. You are quite right - a query string is indeed being constructed. The base URL is a request on the PayPal API to download a page of transactions. The ‘?’ and ‘&’ are used to append key/ value pairs in support of the request.