How can I prevent someone from seeing me online in WhatsApp?

On Android, if you open Whatsapp and got to settings by clicking on the overflow menu (the three dots on the top right). Navigate to the “Account” section and “Privacy”. Here you can find an option for “Last Seen”.
You can choose from three option, “Everyone”, “My Contacts”, “Nobody”; which are self-explanatory. This is a double-edged sword, as mentioned in the Privacy section, “If you don’t share your ‘Last Seen’, you won’t be able to see other people’s ‘Last Seen’”.
So, if you select the ‘Last seen’ as ‘Nobody’, then you wont be able to see other people’s Online status as well.