Why people are fake and how to deal with them..

So I'm sure many of you've come across people who were fake...like they are either really nice to you when you guys are alone and then act totally different when others are around OR they act like they care and everything when everyone's around but when you guys are alone they could care less of what you're doing/saying...how do you deal with these kinds of people? and what is their mindset for acting this way? why can't you be real? do they think they are somewhat better than you or like is status important to them?

one thing I found is that with these kinds of people..i shouldnt waste my time even thinking bout them cause if they think I'm not worth their time then why should I be wasting my precious mentality worrying bout what they're doing...but I'll still be my true self if I come across them and then just forget bout what just happened and continue on with my honest life. so how do you deal with these kinds of people?