So I will take you through the piece of code you have provided as detailed as my free time now can permit me and from the top of my head.
categoryId
is a variable that is accepting the result of what is on the right. thus the =
sign.
categoryId === ''
This part here is simply making a comparison between the results in categoryId
to an empty string ''
which will return a boolean. So its saying "is the result in categoryId
an empty string? true
or false
.
&&
this is saying that we are going to check under condition so check the above one and another...
location.pathname.match(regExp)
this is the 2nd check... checking if a url path matches a certain regex definition/condition in regExp
(you have not provided that so I can't say much there)
Now note that due to the use of &&
, both conditions must return true
before the true
statement is run else it will be false
.
?
this is saying; if true, run the next condition/statement
location.pathname.match(regExp)[1]
this is the condition/statement it will run if result is true.
:
this means if it is false, run the next condition/statement
categoryId
this is the condition to run when the result is false.
This type of conditional statement is called a "Conditional/Ternary Operator" find a bit more details here: https://www.w3schools.com/js/js_comparisons.asp
I hope this helps. If its not clear let me know so I clarify. Best way to learn!