function printAll(strs: string | string[] | null) {
  if (strs && typeof strs === "object") {
    for (const s of strs) {
      console.log(s);
    }
  } else if (typeof strs === "string") {
    console.log(strs);
  }
}
https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Here I have broken the big if statement into two parts as follows. The ... show the part that I am not referring to.
I can understand that here if ( ... typeof strs === "object") { we are comparing the type of the variable because it can contain other types too.
I do not understand this: if (strs === "object" ... ) {. What is the purpose of this statement?





if (strs === "object") {?if (strs && typeof strs === "object")is saying "ifstrsis truthy andstrs's type descriptor is"object"". the double amerpsand (&&) delimits the two conditions.if (typeof strs === 'string'), and not just use} else {,.. It's becausestrscould still be null.