Quick question about Rotation

I sometimes see these lines when a character needs to be rotated. While the first line is clear, I don’t know what the last line (with Euler Angles) is for. I can remove it or not it doesn’t change anything on the result.

transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction),rotationSpeed * Time.deltaTime);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

The last line is kind of a hack (IMO) to ensure that the character stays upright. There are likely better methods that could be used, but what method would be best depends on the circumstances and on where the ‘direction’ variable comes from.