If-statement matches but doesn't give a result
The Arduino IDE uses the C and C++ programming languages.  

Some string comparison basics using C:

In the C programming language, a string can be thought of as an array of 8 bit values.  One way to compare two strings is to compare each 8 bit value and consider the strings different (not equal) upon finding the first not-matching 8 bit value.  Here is an example from programmingsimplified.com: 

int compare_strings(char a[], char b[])
{
   int c = 0;

   while (a[c] == b[c]) {
      if (a[c] == '\0' || b[c] == '\0')
         break;
      c++;
   }

   if (a[c] == '\0' &amp;&amp; b[c] == '\0')
      return 0;
   else
      return -1;
}


There is a common function called strcmp() which can be used instead.  Here is another example from the same web page which uses strcmp():

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main()
{
   char a[100], b[100];

   printf("Enter a string\n");
   gets(a);

   printf("Enter a string\n");
   gets(b);

   if (strcmp(a,b) == 0)
      printf("The strings are equal.\n");
   else
      printf("The strings are not equal.\n");

   return 0;
}


Note that in both cases the array of strings is assumed to end with a NULL or zero value byte.  If you do not wish to follow this format you can use an alternate version of the function called strncmp() where the number of characters to be compared is passed along with pointers to the 2 strings.

Some string comparison options using C++:

There are C++ ways to compare 2 strings which make coding Arduino Sketches easier.  But C++ string manipulation usually requires more RAM.  And RAM is usually in short supply on inexpensive embedded processors.

As the code in the question is written using type String we can explore that approach. And, as there is some concern the strings may have unexpected trailing characters, we will continue to check only the necessary number of characters. In this slightly modified code example from geeksforgeeks.org string s1 is compared with string s2.  But only the first 6 characters are compared:

void compareOperation(string s1, string s2) 
{ 
    // Compares 5 characters from index number 3 of s2 with s1 
    if((s2.compare(0, 6, s1)) == 0) 
        cout &lt;&lt; "Here, "&lt;&lt; s1 &lt;&lt; " are " &lt;&lt; s2; 

    else
        cout &lt;&lt; "Strings didn't match "; 
} 


The number 6 was chosen because "yellow" contains 6 printable characters.  In this way, we can avoid the uncertainty of what character(s) follow the characters that make up "yellow" as received from the serial port.