What are the false values in Javascript
This article introduces the relevant knowledge of "what are the false values in Javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
When a condition is involved, javascript will use the call type to force or implicitly convert a value from one data type to another to evaluate anything in the condition as true (evaluated as true) or false (evaluated as false).
So needless to say, here are six types that are considered to be fake:
Keyword false
Original value undefined
Original value null
Empty string (', ")
Global property NaN
The number 0, such as 0.0,-0, or 0n
So what is true? It's simple, too, and if it's not in the list above, it's true! In other words, as long as it is not fake, it is true. For example, although empty arrays ([]) or similar empty objects ({}) may seem wrong at first glance, they are actually true because they are not in the list above!
One way I like to check the authenticity of a value is to use the double explosion operator! (or the double negative operator also applies)
You can test this in the browser console:
This is the end of the content of "what are the false values in Javascript". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!