Avatar ·

How to check a variable for null, undefined or empty string in JavaScript?

Hi everyone! I just started learning JavaScript and encountered a problem with checking variables for "emptiness".\n\nI have a function that takes a string from the user. Sometimes the user doesn't enter anything, sometimes null comes from the API, and sometimes the variable is not defined at all. I need to write a universal check that will catch all these cases.\n\nI tried writing it like this:\n\n```javascript\nfunction validateInput(value) {\n if (value == null) {\n return "Value is missing";\n }\n // ... then work with value\n}\n```\n\nBut this doesn't catch empty strings. Then I tried:\n\n```javascript\nif (value === null || value === undefined || value === "") {\n```\n\nBut this looks terribly cumbersome, especially when there are many such checks. I also heard about `typeof`, but I don't un